View Full Version : Store with ScriptTagProxy won't work

21 Dec 2010, 2:10 AM
I'm trying to develop a system that will synchronise some data cross-domains, but can't seem to get my store to load anything at all. When I call my synchronise.php script manually, this is what I get:


asdfasdf({"success":true,"error":0,"message":"","data":{"ID":"123","last_update":"2010-12-14 19:41:00"},"number":1});And here's the Ext code for the store:

var store = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: remote_server + 'synchronise.php',
callbackParam: 'asdfasdf'
reader: new Ext.data.JsonReader({
totalProperty: 'number',
root: 'data',
idProperty: 'ID'
{name: 'ID', type: 'string'},
{name: 'last_update', type: 'string'}
var rec = store.getAt(0);
console.log(rec);Firebug's console outputs the following, indicating a failure of some sort (and since you don't get to see the call to the synchronise.php at the other domain, I can't truly debug what's going on, at least not that I know of):


This is my first foray into the world of ScriptTagProxy so I'm obviously missing something here. Any ideas? Thanks.

21 Dec 2010, 3:06 AM
'data' should contain an array of objects instead of a single object.

21 Dec 2010, 3:43 AM
Thanks for spotting that. I've now corrected it (and also the ? parameters in the URL which I omitted above, thinking they weren't relevant; I remember changing the PHP to accept a different string). I am now I am actually seeing the following output in Firebug's Net tab:

stcCallback1001({"success":true,"error":0,"message":"","data":[{"ID":"123","last_update":"2010-12-14 19:41:00"}],"number":1});
I also noticed that, by specifying "callbackParam: 'asdfasdf'" Firebug was showing that it was actually sending a parameter called "asdfasdf" with the value of "stcCallback1001" so perhaps that was also causing problems earlier, too.

But I'm still left with the following output in my console when I try to log store.getCount() and store.getAt(0):

undefinedIt almost seems as if I can't immediately try to log or access this stuff because the ScriptTagProxy must still be working its secret magic behind the scenes? Is there anything else I have to do to get this to work? I have had to resort to some setTimeout() hacks before (particularly trying to focus a grid row on reload) but the docs don't seem to mention having to commit such a sin for ScriptTagProxy.

thanks for your help.

21 Dec 2010, 3:55 AM
Just like with an AJAX loaded store, you will have to wait till the data is returned. The best way to do this is by adding a handler to the stores 'load' event.

Check out the documentation for Ext.data.Store, and scroll down to the 'load' event - when you expand that section there is more information. The Load method of the Store also has details about this.

21 Dec 2010, 11:50 PM
Well, fancy that. Works a treat! I think I spent far too much time staring at the problem and didn't consider a load listener. Thanks a million :-)