PDA

View Full Version : Is it possible to get NOT JSON response using Ext.data.Store?



pshenichnov
28 Nov 2011, 9:02 AM
I'm curious is it possible to get not JSON response using 'jsonp' proxy?

Problem: I have to get cross-domain request to the server that returns response as a simple string. Is it possible to use jsonp proxy for this?

here is the code that looks like working, but only for FF and Crome... I can't get it working for IE.



Ext.define('search', {
extend: 'Ext.data.Model',
fields: []
});

this.store = Ext.create('Ext.data.Store', {
model: 'search',
proxy: {
type: 'jsonp',
root: '',
url: 'some_url_that_return_response_as_text'
}
});



does anybody know what I'm doing wrong? Here is the error that I get in IE9:



SCRIPT5007: Unable to get value of the property 'id': object is null or undefined
ext-all-debug.js, line 25524 character 17



I suspect that I have to configure Store and Proxy somehow, but have no idea how... can't find any information in documentation...

tobiu
28 Nov 2011, 9:51 AM
http://en.wikipedia.org/wiki/JSONP -> padding

you can use a different reader for the proxy (xml or whatever), but since you are triggering a JS callback function, it has to be readable for the browser.

pshenichnov
28 Nov 2011, 11:33 AM
Hi Tobias,
thanks for the suggestion, but I still can't understand how I can replace callback function in JSONP proxy with my own one. I only can see 'callbackKey' parameter and nothing for the function name...

could you provide some quick example?

Thanks for the help,
Alex

tobiu
28 Nov 2011, 11:48 AM
you should be able to specify a reader, like in other proxies:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Proxy-cfg-reader

for the xml-reader, you find configs here (there are other readers in the docs as well)
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Xml

pshenichnov
28 Nov 2011, 1:38 PM
Ok, looks like it fixed... just changed JSON reader on XML. But still don't understand why it happened that way...

Anyway, thanks for the suggestions and help,
Alex