View Full Version : How do I get jsonp proxy callbacks to work?

11 Oct 2011, 11:26 AM
Using Ext 4.0.2a I'm having a problem adding a callback to my jsonp proxy:

Ext.define('pipeline.store.PipelineSearch', {
extend : 'Ext.data.Store',
listeners : {
exception : function() {
model : 'pipeline.model.PipelineSearch',
proxy : {
type : 'jsonp',
callbackKey : 'test',
callback : function(data) {
// there seems to be a bug currently causing a reader config to not be
// instanciated into a reader object. I therefore instanciate a
// reader object rather than reader : { root: ...}
reader : new Ext.data.reader.Json({
root : 'itemsList.item',
model : 'pipeline.model.PipelineSearch'
root : 'itemsList.item',
url : '...'

Running this in FF, I see this error in Firebug:

JSONPCallback is not defined
[Break On This Error] JSONPCallback ( {"itemsList": {

Removing the callbackKey allows the proxy to work normally, but without the callback. I tried creating a JSONPCallback function to see what would happen. It gets called, but the store never receives the data.

Any ideas on what might be wrong or how to troubleshoot/fix this?



11 Oct 2011, 1:46 PM
I'm confused about what you're trying to do.

As far as I can tell, the JSON-P proxy doesn't support a callback option.

In a JSON-P context, the 'callback' usually refers to the function used to wrap the data. It's a fundamental part of the mechanism used to communicate between the server and client, not a custom function you can provide. If you're unclear about how this works I'd suggest reading the introduction here:


The callbackKey must use the same value that the server is expecting. You can't just set it to an arbitrary value like test. It specifies the name of a request parameter. This request parameter is used to tell the server the name of the callback function. If you use the wrong value then the server will probably just use a default function name (which seems to be JSONPCallback in your example).