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.

melba
14 Jul 2014, 11:46 AM
I wrote a lttle Sencha Touch App and compiled it as cordova android native.

All is fine, but....

the JSONP Ajax call behaves entirely different in the native app as it does from a browser



name: _dc, value: 1405366253614
({"passwd":"","vorname":"Peter","status":"invalid","nachname":"Betzler","login":"Peter"})CONTENT_LENGTH = 91<br>
CONTENT_TYPE = application/json<br>
DOCUMENT_ROOT = /var/www/datapat<br>
GATEWAY_INTERFACE = CGI/1.1<br>
HTTP_ACCEPT = */*<br>
HTTP_ACCEPT_ENCODING = gzip,deflate<br>
HTTP_ACCEPT_LANGUAGE = de-DE,en-US;q=0.8<br>
HTTP_CONNECTION = keep-alive<br>
HTTP_HOST = www.datapat.de<br>
HTTP_ORIGIN = file://<br>
HTTP_USER_AGENT = Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.
0 Chrome/33.0.0.0 Mobile Safari/537.36<br>
HTTP_X_REQUESTED_WITH = XMLHttpRequest<br>
PATH = /usr/local/bin:/usr/bin:/bin<br>
QUERY_STRING = _dc=1405366253614<br>
REMOTE_ADDR = 46.244.135.88<br>
REMOTE_PORT = 54674<br>
REQUEST_METHOD = POST<br>
REQUEST_URI = /perl/PLS/login.pl?_dc=1405366253614<br>
SCRIPT_FILENAME = /var/cgi-bin/datapat/PLS/login.pl<br>
SCRIPT_NAME = /perl/PLS/login.pl<br>
SERVER_ADDR = 195.122.150.137<br>
SERVER_ADMIN = webmaster@localhost<br>
SERVER_NAME = www.datapat.de<br>
SERVER_PORT = 80<br>
SERVER_PROTOCOL = HTTP/1.1<br>
SERVER_SIGNATURE = <address>Apache/2.2.14 (Ubuntu) Server at www.datapat.de (http://www.datapat.de) Port 80</address>
<br>
SERVER_SOFTWARE = Apache/2.2.14 (Ubuntu)<br>
Login:
Passwd:
POST: {"login":"","passwd":"","vorname":null,"nachname":null,"status":null,"id":"ext-record-346"}
({"passwd":"","vorname":"Peter","status":"invalid","nachname":"","login":"Peter"})



The Ajax request is considered to be REQUEST_METHOD = POST
No QUERY parameters are visible.

Now the same as sencha cmd app in android device crome browser



name: passwd, value:
name: _dc, value: 1405366753603
name: page, value: 1
name: callback, value: Ext.data.JsonP.callback8
name: limit, value: 25
name: start, value: 0
name: login, value: Peter
Ext.data.JsonP.callback8({"passwd":"","vorname":"Peter","status":"valid","nachname":"","login":"Peter"})DOCUMENT_ROOT
= /var/www/dataxxx<br>
GATEWAY_INTERFACE = CGI/1.1<br>
HTTP_ACCEPT = */*<br>
HTTP_ACCEPT_ENCODING = gzip,deflate,sdch<br>
HTTP_ACCEPT_LANGUAGE = de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4<br>
HTTP_CONNECTION = keep-alive<br>
HTTP_HOST = www.dataxxx.de<br>
HTTP_REFERER = http://www.dataxxx.de:1841/<br>
HTTP_USER_AGENT = Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.
0.1916.141 Mobile Safari/537.36<br>
PATH = /usr/local/bin:/usr/bin:/bin<br>
QUERY_STRING = _dc=1405366753603&login=Peter&passwd=&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback8<br>
REMOTE_ADDR = 46.244.135.88<br>
REMOTE_PORT = 54695<br>
REQUEST_METHOD = GET<br>
REQUEST_URI = /perl/PLS/login.pl?_dc=1405366753603&login=Peter&passwd=&page=1&start=0&limit=25&callback=Ext.data.JsonP.callb
ack8<br>
SCRIPT_FILENAME = /var/cgi-bin/dataxxx/PLS/login.pl<br>
SCRIPT_NAME = /perl/PLS/login.pl<br>
SERVER_ADDR = 195.122.150.137<br>
SERVER_ADMIN = webmaster@localhost<br>
SERVER_NAME = www.dataxxx.de<br>
SERVER_PORT = 80<br>
SERVER_PROTOCOL = HTTP/1.1<br>
SERVER_SIGNATURE = <address>Apache/2.2.14 (Ubuntu) Server at www.dataxxx.de (http://www.dataxxx.de) Port 80</address>
<br>
SERVER_SOFTWARE = Apache/2.2.14 (Ubuntu)<br>
Login: Peter
Passwd:
POST:
Ext.data.JsonP.callback8({"passwd":"","vorname":"Peter","status":"valid","nachname":"","login":"Peter"})


Now the Ajax call is fine and is a GET Request and I see my QUERY Parameters.

Can anybody help?

Thank you

Peter