PDA

View Full Version : Store proxy JSONP : callback is not defined



alexsai
26 Mar 2014, 3:25 AM
I need to query solr and with this code i recive the data wrapped into the given callback 'call()'.
However chrome says that the callback is not defined. Is there somethin im doing wrong?
I did this with Ext.data.JsonP.request but i prefer to use the store because its more clean.


Ext.define('Pgl.store.SolrStore',{
extend:'Ext.data.Store',
model:'Pgl.model.SolrResult',
proxy: {
type:'jsonp',
url: 'solrserver/select?json.wrf=call',
extraParams: {
q: '*:*',
wt: 'json',
indent: true
},
reader:{
type: 'json',
root: 'result.response.docs'
},
callbackKey: 'call'
},
autoLoad:true
});

Uncaught ReferenceError: call is not defined

Farish
26 Mar 2014, 11:10 AM
try this:


Ext.define('Pgl.store.SolrStore',{
extend:'Ext.data.Store',
model:'Pgl.model.SolrResult',
proxy: {
type:'jsonp',
url: 'solrserver/select?json.wrf=call',
extraParams: {
q: '*:*',
wt: 'json',
indent: true
},
reader:{
type: 'json',
root: 'result.response.docs'
},
callbackKey: 'call',
call: function()
{
console.log("call");
}
},
autoLoad:true
});

alexsai
1 Apr 2014, 1:21 AM
I had no luck with this either. Chrome still says that the callback is no defined.

According to the documentation:

As soon as the script finishes loading, the 'someCallback' function that we passed in the url is called with the JSON object that the server returned.
JsonP proxy takes care of all of this automatically. It formats the url you pass, adding the callback parameter automatically. It even creates a temporary callback function, waits for it to be called and then puts the data into the Proxy making it look just like you loaded it through a normal AjaxProxy (http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.data.proxy.Ajax).

What I understand from this statement is that the store automatically creates the callback and parse the data.

Another problem could be that, according to docs, that data must be format in this way:


someCallback({ users: [ { id: 1, name: "Ed Spencer", email: "ed@sencha.com" } ]});

skirtle
2 Apr 2014, 12:06 PM
Remove the json.wrf from the URL and instead add this to your proxy:


callbackKey: 'json.wrf'

alexsai
2 Apr 2014, 12:53 PM
json.wrf=call is needed to Solr server in order to send me jsonp data wrapped into call function specified in that parameter. If I omit it Solr sends a normal json response which violate the cross domain origin policy

skirtle
2 Apr 2014, 1:54 PM
It will be added automatically if you set the callbackKey correctly.

alexsai
3 Apr 2014, 4:38 AM
Now i understood, thank you :)