tags:

views:

76

answers:

1

Hi all

I understand that it's not possible request JSON data from a remote domain due to XSS vulnerabilities:

    Ext.Ajax.request({
        method: 'GET',
        url: 'remoteurl.php'
    });

So the alternative is to use a ScriptTagProxy and a JSONStore:

   store = new Ext.data.JsonStore({
        autoLoad: true,
        proxy: new Ext.data.ScriptTagProxy({
            url:'remoteurl.php',
             restful: true
    })
});

The problem is that I can't seen to harness the response at all from this request. Although I can print the data to console (store.reader.jsonData), I can't seem to persist it (probably due to it being asynchronous).

Ideally what I'd like to do is get the XmlHttpResponseText as a JSON object in full from the request - specifying the mappings for the JSONStore is not an option in this scenario as I can't predict what the fields are going to be.

Is there any way, by using the JsonStore, to grab the entire response as an object?

Thanks!

+1  A: 

Hm, I can't believe that's possible, the ScriptTagProxy is just really a script tag in the end.

Onkelborg
So is there anyway in getting a JSON result without mapping it onto fields?
Alan Grant
Hm, I don't really get what's the problem actually. As you say, you can access the data with store.reader.jsonData. I don't know if it's a timing problem you are suffering from, but since it's async you haev to wait for the load-event to fire on the store before you try to access the data
Onkelborg
I've added a load event listener, but is there anyway to persist the data from within that event? I can access the store data from here, but I need to use it elsewhere in the application and var test = store.reader.jsonData doesn't persist the data. Do I need to do all data handling from within this listener? Ajax.Request does exactly what I want but can't do cross-domain!
Alan Grant
Hm, now I don't follow you. What's your definition of persist? Can you give a full example? (This short example you presented here rather seems to be a problem with scope.)
Onkelborg
Cheers for your help; it was a scope problem. To resolve, I've added the logic in the load event handler rather than outside it in the application...
Alan Grant