PDA

View Full Version : [CLOSED] Ajax/JSONP request doesn't work..



robl
24 Oct 2011, 11:29 AM
I am trying to call a remote server that returns JSON using Ajax. I am using ST 2.0.0pr1 and phonegap 1.1.0.

I do not understand why this doesn't work:



Ext.Ajax.request({
url: url,
success: function(response) {
console.log(response);
// process server response here
}
});


while this does:



var ajax = new XMLHttpRequest();
ajax.open("GET",url,true);
ajax.send(); ajax.onreadystatechange=function(){
console.log('ajax response!');
if(ajax.readyState==4 && (ajax.status==200)){
console.log('200 response!')
console.log(ajax.responseText);
}

jedi
25 Oct 2011, 1:56 AM
hi,

this is probably due to the new whitelist feature of phonegap. if you're working on xcode you should be able to add domain names in file PhoneGap.plist (under <project name>/Supporting Files). there's a section called ExternalHosts. add your remote domains there (wildcards work).

here's a screenshot: http://www.prosoxi.com/2011/10/08/xcode-phonegap-white-list-rejection/

robl
25 Oct 2011, 6:29 AM
Unfortunately, that's not the problem because I already have the server host name in the whitelist and it works with a straight Javascript AJAX request.

jay@moduscreate.com
25 Oct 2011, 2:06 PM
I'll be honest. I don't think that this is a Sencha touch issue. Try using this inside of mobile safari. Does it work? Also, try setting a failure callback and inspecting the results.

robl
25 Oct 2011, 2:09 PM
I'll be honest. I don't think that this is a Sencha touch issue. Try using this inside of mobile safari. Does it work? Also, try setting a failure callback and inspecting the results.

Thanks. So my above code looks right?

And should the failure callback look like this below?




failure: function(response) { console.log(response); // process server response here }

knifegun
4 Nov 2011, 9:00 AM
I also think this has to be an issue with whitelisting and/or issues with your code. I can run Sencha Touch 2 via PhoneGap 1.1 on iOS. It makes JSONP calls successfully.

rdougan
5 Nov 2011, 9:03 PM
I heard reports of this at SenchaCon too. Moving this to the bug forum so we can investigate and verify.