PDA

View Full Version : JSONP request



chechuironman
6 Nov 2013, 4:58 PM
Hey guys,

I'm trying to store the return of a JSONP request in variables:

var details = 'http://127.0.0.1:4567/details?type='+record;
Ext.data.JsonP.request({
url: details,
crossDomain: true,
type: "GET",
dataType: "json",
callbackKey: 'callback',
scope: this,
callback: function (response, value, request) {
var result = Ext.decode(response.responseText);
alert(value.CPU);
}
});

The url returns a json chain where CPU is one of the properties. The only thing that I get is is undefined object.

Could you help me?

Thanks in advance

scottmartin
8 Nov 2013, 6:02 AM
Is your response formatted correctly? As a callback function:
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.proxy.JsonP

skirtle
9 Nov 2013, 1:26 PM
That request is full of settings that don't do anything. Cutting it back to something a bit more intelligible:


var details = 'http://127.0.0.1:4567/details?type=' + record;

Ext.data.JsonP.request({
scope: this,
url: details,

callback: function(success, result, errorType) {
if (success) {
alert(result.CPU);
}
}
});

Or even better:


Ext.data.JsonP.request({
scope: this,
url: details,

success: function(result) {
alert(result.CPU);
}
});

Of course, all this assumes a valid JSON-P response from your server using the correct callback name. Note that there are two totally separate concepts that are called 'callback' in the context of a JSON-P request and it's important not to get confused between them.