PDA

View Full Version : $_GET['callback'] variable always empty



henk.burgstra
24 Apr 2007, 1:58 PM
I use code from the Basics of Paging with the Grid Component Tutorial:
http://extjs.com/tutorial/basics-paging-grid-component

My problem is that the $_GET['callback'] variable is always empty. I use HttpProxy and method: 'get'. With Firebug I can see that te JSON-data is returned OK, just without the callback wrapper. Needless to say my grid doesn't get populated. Also with Firebug I can see that the only GET-parameters transferred are: 'dir', 'limit', 'sort' and 'start'. 'callback' is missing.

Any ideas why?

dfenwick
24 Apr 2007, 5:03 PM
I use code from the Basics of Paging with the Grid Component Tutorial:
http://extjs.com/tutorial/basics-paging-grid-component

My problem is that the $_GET['callback'] variable is always empty. I use HttpProxy and method: 'get'. With Firebug I can see that te JSON-data is returned OK, just without the callback wrapper. Needless to say my grid doesn't get populated. Also with Firebug I can see that the only GET-parameters transferred are: 'dir', 'limit', 'sort' and 'start'. 'callback' is missing.

Any ideas why?

Short answer:

The callback parameter on the request is only sent when using the ScriptTagProxy object. You're using the HttpProxy which does not require a callback at all. You just have to return JSON data from your script. The server request must be to a URL on the server your Javascript originated from.

A slightly more detailed answer:

Cross-site data retrieval is blocked by ajax implementations due to the possible security ramifications of such. ScriptTagProxy slightly relieves this by allowing your application to access data on sites that you control. The way it works is this:

- You add ScriptTagProxy with the site you control as the proxy for your store
- You execute load()
- Inside ScriptTagProxy() it wrappers up the ajax call with an additional auto-generated callback param in your http request
- The script you write to retrieve data sees the callback header in the http headers and uses that to write a Javascript function call that's returned to your javascript application.
- When the data comes back, it's inserted into your DOM as a script object. Since it's a function call, it calls whatever function name callback was set to and passes the json object you returned from your script to that function.
- That json object is then evaluated and returned, and the return object is placed in your store.

Animal
24 Apr 2007, 11:51 PM
Only wrap the data up in a call to whatever was in the "callback" parameter if that parameter was passed.

That way, your service can be used by both HttpProxies and ScriptTagProxies.