Results 1 to 5 of 5

Thread: Store with ScriptTagProxy won't work

  1. #1
    Sencha User
    Join Date
    Aug 2009
    Location
    Tamworth, NSW, Australia
    Posts
    32

    Question Store with ScriptTagProxy won't work

    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:

    synchronise.php?callback=asdfasdf

    Code:
    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:

    Code:
             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'}
                ])
            });
            store.load();
            console.log(store.getCount());
            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):

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

  2. #2
    Sencha User VinylFox's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD
    Posts
    1,501

    Default

    'data' should contain an array of objects instead of a single object.

  3. #3
    Sencha User
    Join Date
    Aug 2009
    Location
    Tamworth, NSW, Australia
    Posts
    32

    Default

    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:

    Code:
    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):
    Code:
    0
    undefined
    It 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.

  4. #4
    Sencha User VinylFox's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD
    Posts
    1,501

    Default

    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.

  5. #5
    Sencha User
    Join Date
    Aug 2009
    Location
    Tamworth, NSW, Australia
    Posts
    32

    Default

    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 :-)

Similar Threads

  1. Does ScriptTagProxy work with XmlReader?
    By dkann in forum Ext GWT: Discussion
    Replies: 16
    Last Post: 6 May 2010, 12:49 AM
  2. Adding records to the store won't work
    By Raz_ in forum Ext 2.x: Help & Discussion
    Replies: 8
    Last Post: 30 Jun 2008, 5:35 AM
  3. [Solved][2.0]Not able to get ScriptTagProxy to work...
    By cginzel in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 27 Dec 2007, 3:14 PM
  4. Code won't work in IE7, no JS errors, just doesn't work
    By blackwaterdev in forum Ext 1.x: Help & Discussion
    Replies: 6
    Last Post: 17 Sep 2007, 5:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •