PDA

View Full Version : Get json string from a URL and store in an object or array



spor
11 Feb 2011, 7:13 AM
Is it possible to retrieve data from a jsonstring that comes from a URL? I just want to use it to compare one datafield from the jsonstring.

I know it's possible to use a grid with a jsonstore to do this, but that is way overkill, since I havent been able to load the store without loading the grid too.

arthurakay
11 Feb 2011, 8:48 AM
If I understand you correctly, you want grab some JSON string from the server:

{ "key" : "some value" }

You could easily just use Ext.Ajax.request(). In your success callback, decode the response text using Ext.decode(). Then compare your values.

Is that what you're attempting to do? If not, feel free to elaborate a bit more.

spor
14 Feb 2011, 12:22 AM
If I understand you correctly, you want grab some JSON string from the server:

{ "key" : "some value" }

You could easily just use Ext.Ajax.request(). In your success callback, decode the response text using Ext.decode(). Then compare your values.

Is that what you're attempting to do? If not, feel free to elaborate a bit more.

Yes, that is what I am attempting. Where can I save the data then, if it's not in a Store? Is it possible to just save the data to a plain object, doing your way?

I can see that it is done your way, when it comes to FormPanel. But, how do you do that with an independent store or object? Could you give me an example?

steffenk
14 Feb 2011, 1:16 AM
store data of any kind - that's a store.

arthurakay
14 Feb 2011, 6:29 AM
var dataObj = null;

Ext.Ajax.request({
url:'/getData.php',
params: { foo: 'bar' },
failure: function(response, options) {},
success: function(response, options) {
//assuming the response is a JSON string...
dataObj = Ext.decode(response.responseText);

//add any other logic you want here
}
});