PDA

View Full Version : How to trigger the callback function of Ext.util.JSONP.request by jsp



derryflag
18 Jul 2011, 11:04 PM
Hi all,
I want to send a JSONP request to a jsp page and get json data for my app ,with code as follows:

Ext.setup({
onReady: function() {
var makeJSONPRequest = function() {
//Ext.getBody().mask('Loading...', 'x-mask-loading', false);
Ext.util.JSONP.request({
//url:'http://localhost:8888/sel_st/serv.jsp',
url:'http://124.16.139.80/sel_st/serv.jsp',
//url: 'http://www.worldweatheronline.com/feed/weather.ashx',
callbackKey: 'callback',
params: {
//key: '23f6a0ab24185952101705',
// palo alto
//q: '94301',
format: 'json'
//num_of_days: 5

},
callback: function(result) {
Ext.Msg.alert('title','content');
}
});
};
var func1 = function(){
Ext.util.JSONP.callback();
};

new Ext.Panel({
fullscreen: true,
id: 'content',
scroll: 'vertical',
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
text: 'TEST JSON',
handler: makeJSONPRequest
},{xtype: 'spacer'},{
text: 'XMLHTTP',
handler: func1
}]
},{
id: 'status',
xtype: 'toolbar',
dock: 'bottom',
title: "Tap a button above."
}]
});
}
})
however ,callback: function(result) won't be called. My jsp can be visited in a browser: http://124.16.139.80/sel_st/serv.jsp?callback=Ext.util.JSONP.callback&format=json
and I made it to have exactly same content with the following page: http://www.worldweatheronline.com/feed/weather.ashx?key=23f6a0ab24185952101705&q=94301&format=json&num_of_days=5
however ,the latter page can trigger Ext.util.JSONP.callback() but the former one won't.
In sencha touch examples talks only about php examples, and I cannot find jsp examples, who could help me to figure out the problem or give me an example? With great thx!

derryflag
19 Jul 2011, 12:57 AM
OK?problem has been solved ?wrap the json string with Ext.util.JSONP.callback (); that is : Ext.util.JSONP.callback ({...}); then the callback: function(result) will be called ,thx to all!