View Full Version : Models, localstorage, store and remote JSON

25 Dec 2010, 12:45 PM

I have a remote JSON feed that i would like to pass through a model and save in html 5 localstorage using a store. i found some sample code for this in the API Docs.

// Set up a model to use in our Store
Ext.regModel('User', {
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'age', type: 'int'},
{name: 'eyeColor', type: 'string'}

var myStore = new Ext.data.Store({
model: 'User',
proxy: {
type: 'ajax',
url : '/users.json',
reader: {
type: 'json',
root: 'users'
autoLoad: true

Now the example here uses a local JSON URL..My JSON feed is remote..Will the above code work if i change the url to http://xyz.com/sample.json ?

Or does JSONP come into play somewhere..If so how?


26 Dec 2010, 7:49 AM
The AjaxProxy will not allow cross-domain calls. You will have to use JSONP or ScriptTagProxy. I believe they work similar with JSONP getting a lot of traction if I may call it that.

26 Dec 2010, 8:31 AM
thanks mitchell but how will i adjust the code above to achieve this cross domain call?
i cant seem to find any example of this anywhere..


26 Dec 2010, 8:44 AM
Look at the examples. The kitchen sink demo hs a good JSONP EXAMPLE. ScripTagProxy works the same as the other Proxies

26 Dec 2010, 9:39 AM
I have looked at this example but it only shows how to get to the remote JSON Data..not how to move it to localstorage....

26 Dec 2010, 2:05 PM
There is another proxy called LocalStorageProxy. This will add files to the HTML5 browser database so you will need an offline Store. Take not of the Store's sync function though.