PDA

View Full Version : ajax not working in android emulator



zuppy
22 Aug 2011, 1:53 AM
hi all,

my application have been running fine during development on chrome..... it has a simple login page, using ajax to retrieve user's information. but when i tried to run in an android emulator, it keep returning http code :0 .... i would like to ask must i deploy my app using phonegap inorder for my ajax to run in android emulator?

dschano
2 Mar 2012, 3:58 AM
hello

i have the same problem on a real device!
this:

Ext.Ajax.defaultHeaders = {
'Accept': 'application/json'
};
Ext.Ajax.request({
url:'http://www.xxx.xx/xxx.php' (http://www.sencha.com/forum/'http://www.xxx.xx/xxx.php'), // gives back a jsonlint validated json
params:{task:'personal_st', beratercode:br_code},
method:"POST",
success:function(response){
alert("Success :"+response.status+' '+response.responseText);
},
failure:function(response){
alert("Error :"+response.status+' '+response.responseText);
}
});

works with success in CHROME.
But not on Android Devices (either 3.01 and 3.2).

regards

atula_a1
5 Mar 2012, 12:14 AM
Hi.
I thing: this is a problem when use phonegap to build native app on Android( iOS)
"Ext.Ajax.request" only can working when the browser. Method post, get are methods of browser when send request.

I try few options to replace " Ext.Ajax ". But not working!

Somebody have suggestion?

dschano
5 Mar 2012, 1:15 AM
i have the problem on a normal browser application, no phonegap in use...

atula_a1
5 Mar 2012, 3:23 AM
@dschano:

Your ajax request not working because you used attribute url in Ajax request is incorrect.
This attribute don't allow use IP. Correct is:
Example my server is: http://localhost:8888/myapp
then :
Ext.Ajax.request({
url : '/myapp/getUser', // or url: 'getUser'
method : 'post',
scope : this,
success: function(response, opts) {
...
},
failure: function(response, opts) {
....
}

dschano
5 Mar 2012, 3:49 AM
Thank you very much.

always these small stones in the shoe... ;)