PDA

View Full Version : problem: Store with JSON response



paula.mansour
27 Mar 2011, 10:20 PM
I need your help please.
Simply I want consume this JSON service "http://zrivera.com/extjs4/fields.json".

Here is my code, but it doesn't work please help.


var fieldsStore = new Ext.data.JsonStore({
autoLoad:true,
root: 'fields',
idProperty: 'name',
proxy : new Ext.data.ScriptTagProxy({
url:'http://zrivera.com/extjs4/fields.json'
}),
fields: [ 'name' ]
});

Thanks

Grolubao
27 Mar 2011, 11:39 PM
Not sure it's returning with the JSON header so maybe that's the reason why it's not binding.

Also not sure you should use ScriptTagProxy instead of HttpProxy, it depends on your domain

paula.mansour
28 Mar 2011, 1:40 AM
Thank you Grolubao for your replay.
I'm using "ScriptTagProxy" because it's cross domain.

What should I do, please help...

Thanks

Grolubao
28 Mar 2011, 1:43 AM
Can you try using the method : 'GET' property in the proxy? I think by default is POST

Grolubao
28 Mar 2011, 1:46 AM
Ok, I checked using FF and your http://zrivera.com/extjs4/fields.json is returning the header with plain-text instead of Json so this way it will never bind.

You need to change your service to return to contentType JSON

paula.mansour
28 Mar 2011, 1:51 AM
Okay, Thank you very much.
I'll check it, and I replay back if it works or not.

Again, Multi-million thanks :)

Grolubao
28 Mar 2011, 5:22 AM
This may be useful as well:

The content passed back from a server resource requested by a ScriptTagProxy must be executable JavaScript source code because it is used as the source inside a <script> tag.

paula.mansour
28 Mar 2011, 7:45 AM
If it used as a executed as script, what should I do?

Should I return for example:

fieldsStore = {fields:[{'name':'month'},{'name':'Rep1'},{'name':'Rep2'},{'name':'Rep3'},{'name':'Rep4'},{'name':'Rep5'}]};