Phonegap Android HTTPS Ajax Requests don't work

2,453 views
Skip to first unread message

Alp

unread,
Jul 8, 2011, 1:12:35 AM7/8/11
to phonegap
I am developing a phonegap application on Android which uses ajax
requests to the server with https protocol. The SSL certificate that
the server uses now is trusted and verified ( you can check it if you
want to: https://www.korebe.com/Android/Bilgi ) but result of the
xmlhttp requests is always blank due to https connection.

Same version of the on http is works fine but I want to connect
through https.

What could be reason behind this issue?

Thanks.

AbhishekKanitkar

unread,
Jul 8, 2011, 1:42:48 PM7/8/11
to phonegap
Use the following code to which shows that you are getting valid json
response even though the request is https.
I tested just now on Android 2.1 emulator.
I used Dojo's ajax api method to get json data.
handleAs:"json" saves you from using json parser in javascript.

You can also use jQuery's Ajax api methods to fetch json data array.

--------------------------------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /
>
<title>Test Ajax HTTPS</title>
<script type="text/javascript" src="dojo/dojo.js"
djConfig="parseOnLoad: true"></script>
<script type="text/javascript">

dojo.require("dojox.mobile.parser");
dojo.require("dojox.mobile");

dojo.requireIf(!dojo.isWebKit, "dojox.mobile.compat");

function test(){

dojo.xhrGet({
// The URL to request
url: "https://www.korebe.com/Android/Bilgi",
handleAs:"json",
// The method that handles the request's successful result
// Handle the response any way you'd like!
load: function(result) {
alert("The message is: " + result.ucret_sms);
}
});


}


</script>
</head>
<body onload="test()">
yes
</body>
</html>

--------------------------------------------------------------------------------------------------------

On Jul 8, 10:12 am, Alp <dral...@gmail.com> wrote:
> I am developing a phonegap application on Android which uses ajax
> requests to the server with https protocol. The SSL certificate that
> the server uses now is trusted and verified ( you can check it if you
> want to:https://www.korebe.com/Android/Bilgi) but result of the

Christian Grobmeier

unread,
Jul 8, 2011, 1:45:56 PM7/8/11
to phon...@googlegroups.com
>> I am developing a phonegap application on Android which uses ajax
>> requests to the server with https protocol. The SSL certificate that
>> the server uses now is trusted and verified ( you can check it if you
>> want to:https://www.korebe.com/Android/Bilgi) but result of the
>> xmlhttp requests is always blank due to https connection.

Is youre server really getting the request?
I have found out that on Android (jquery mobile) not all ajax
requests are send for an unknown reason. Sometimes I got a blank
response back, even when the server never got an actual request

>>
>> Same version of the on http is works fine but I want to connect
>> through https.
>>
>> What could be reason behind this issue?
>>
>> Thanks.
>

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com
>

--
http://www.grobmeier.de

Alp Oral

unread,
Jul 10, 2011, 5:29:07 AM7/10/11
to phon...@googlegroups.com
OK dojo is working fine but what is the difference?; why shouldn't I use the native xmlhttp request on https but http; What is wrong in my code ?

I am using a simple post request like:

var xmlhttp;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
try{
xmlhttp.open("POST",webPage,false);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(data);
}catch(e){alert(e)}
return xmlhttp.responseText;

2011/7/8 AbhishekKanitkar <kanitkar...@gmail.com>

Alp Oral

unread,
Jul 10, 2011, 5:35:46 AM7/10/11
to phon...@googlegroups.com
By the way the code you sent is worked for simulator but when i installed the apk to the device it didn't worked. Any ideas? 

2011/7/8 AbhishekKanitkar <kanitkar...@gmail.com>

Jeff Meyerhoff

unread,
Feb 14, 2012, 3:34:37 PM2/14/12
to phon...@googlegroups.com
I'm having the same issue with making an ajax request on Android.  The ajax request seemingly does nothing.  It does not return successfully and it does not return an error.  Running the exact same code on iOS or from within a browser (Chrome/Safari), it works perfectly. 

I have tested this same code with no success on two separate 3.1 devices (Iconia, Galaxy Tab), a 4.0.2 Galaxy Nexus, and 4.0.3 in emulation.  However, this works on an emulator running Gingerbread 2.3.3.  This leads me to believe that either the way HTTPS within a WebView changes on Android 3.0+ or Phonegap is unintentionally interfering with the WebView on 3.0+.  Any thoughts?

Note:
The offending setup: Android 4.0.2 Galaxy Nexus, Phonegap 1.4.1, JQuery 1.7.1, and JQuery Mobile 1.0.1
I have the uses-permission tag in my app manifest for android.permission.INTERNET and my phonegap.xml contains <access origin=".*" />

Aater Suleman

unread,
Feb 14, 2012, 4:40:00 PM2/14/12
to phonegap
I am not familiar with dojo but is this jsonP or JSON. jsonP works
great for me on 3 different phones with no problem.

Jeff Meyerhoff

unread,
Feb 14, 2012, 5:02:38 PM2/14/12
to phon...@googlegroups.com
Aater,
  Are any of the phones you mentioned running Android?  If so, what version Android are they running?

Thanks
Reply all
Reply to author
Forward
0 new messages