Ext.util.JSONP.request({
url: '/Home/GetMessagesMobile',
callbackKey: 'callback',
params: {
lat: geoip_latitude(),
lng: geoip_longitude(),
rad: 1,
sType: 0,
flow: 1,
lastId: 0,
lastRow: 0,
uniqueify: Math.random()
},
callback: function (data) {
var messages = data;
alert(messages);
home.update(messages); // refresh messages
}
});
I can debug and hit the breakpoint of my MVC action, and confirm that data is being returned by the action, however, the alert
never gets shown, and nothing happens on the client side. Looks like it's not entering the callback
for some reason.
Do I need to make this request different? I'm returning a Json
result from the action. Here is the code:
return Json(retval);
Where retval
is a list of objects that match the html template parameters elsewhere in the sencha code. Even if that part doesn't match though, I should at least be able to see the alert right?
You are using JSONP
, you should use Ext.util.JSON
JSONP works in another way, returning JavaScript instead of JSON.
I don't use Sencha/Ext a lot, so I could be way off base here, but shouldn't that be:
Ext.Ajax.request({
url: '/Home/GetMessagesMobile',
params: {
lat: geoip_latitude(),
lng: geoip_longitude(),
rad: 1,
sType: 0,
flow: 1,
lastId: 0,
lastRow: 0,
uniqueify: Math.random()
},
success: function(data) {
console.log(data);
}
});
You are probably make a cross-domain request, in that case, you must use JSONP.
And using JSONP, makes impossible to use return Json(object)
from the controller.
Check the JSONP class in the API. There is a example for ASP.NET. You can use in JavaScriptSerializer class to serialize an object to JSON. (In fact, Json method is using this class in the back).
The idea is you have to return something like this:
var myJson = {success:true};
someRandomMethod(myJson); // someRandomMethod is the callback parameter