This is a migrated thread and some comments may be shown as answers.

Ajax call on Jelly Bean not working

7 Answers 117 Views
Report a bug
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcus
Top achievements
Rank 1
Marcus asked on 03 Jan 2013, 11:41 PM
I'm working on an app that talks to my database through Ajax jQuery calls. The backend is a WCF webservice. This was working fine.
Then I got a new Android (HTC DNA) which comes with Jelly Bean 4.1.1. Now my POST ajax calls no longer work. If I make a GET it works, but not with a POST.
My webservice is receiving the POSTs, as they are showing up in my logs, but my phone never receives the response. it will just wait until it times out.

Searching online didn't bring up anything (except http://stackoverflow.com/questions/12409440/phonegap-cordova-app-breaks-in-jelly-bean-access-control-allow-origin-and-seta , but I'm not sure if it applies here).

Can somebody confirm for me that they have an app on Jelly Bean that can successfully create Ajax POSTs? Or why the app would stop working for me all of a sudden? (It still works on older OS versions).

Thanks!
















7 Answers, 1 is accepted

Sort by
0
Jan-Dirk
Top achievements
Rank 1
answered on 04 Jan 2013, 12:04 AM
Just a wild guess... Could it be that your web service is on the same network as where you phone is on? Some routers do not support "loopback", meaning that you cannot access a local PC via the external IP of the local network.

On a Windows PC you would change the hosts file to circumvent this
0
Marcus
Top achievements
Rank 1
answered on 04 Jan 2013, 03:03 PM
I connected my phone to our internal network through wifi, which is the same network our dev webserver is on. So yes, they are on the same network, but that wasn't a problem before, and still isn't with other phones on different OS versions.
0
Kristian D. Dimitrov
Telerik team
answered on 07 Jan 2013, 10:46 AM
Hello Marcus,

 I tried to reproduce the issue you reported, using Samsung Galaxy S3 with Android 4.1.1, but to no avail. Unfortunately, we don't have HTC DNA testing device. I wrote a very simple example using a weather service. I'd appreciate it if you could give it a try. Here is the sample:

HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>Hello, World</title>
        <link href="jquery-mobile/jquery.mobile-1.2.0.min.css" rel="stylesheet" type="text/css" />
        <link href="styles/main.css" rel="stylesheet" type="text/css" />
 
        <script src="cordova.js" type="text/javascript"></script>
        <script src="jquery-mobile/jquery-1.8.2.min.js" type="text/javascript"></script>
        <script src="jquery-mobile/jquery.mobile-1.2.0.min.js" type="text/javascript"></script>
        <script src="js/hello-world.js" type="text/javascript"></script>
    </head>
    <body>
        <button id="test"></button>
    </body>
    <script type="text/javascript">
            app.initialize();
    </script>
</html>


JavaScript:

var app = {
    initialize: function() {
        document.getElementById("test").addEventListener("click", this.getResposne);
    },
 
    getResposne:function () {
        $.ajax({
                    type:"POST",
                    data:{zip:"34464"},
        }).done(function( msg ) {
                    console.log( msg );
                });
    }
};


Just create an empty jQuery project and copy the html part inside the index.html and the JavaScript part inside hello-world.js. All the best,
kdimitrov
the Telerik team

Share feedback and vote for features on our Feedback Portal.
Want some Kendo UI online training - head over to Pluralsight.
0
Marcus
Top achievements
Rank 1
answered on 07 Jan 2013, 03:25 PM
Well, that service worked on my device. I guess it must be something on my end. I'll keep looking. Thanks for looking at it for me.
0
Marcus
Top achievements
Rank 1
answered on 18 Jan 2013, 07:11 PM
After a huge amount of more debugging, I've narrowed it down to when my webservice sends the response with an HttpStatusCode of "Unauthorized" / "401". Setting the response statuscode to anything other than 401 works fine.

This fellow (http://stackoverflow.com/questions/10305181/android-phonegap-ajax-does-not-fire-callback-for-unauthorized-401) had the same problem, and apparently fixed it by reverting to an older version of Cordova.
This is not a good fix. (I'm on v2.2.0).

I've also found the problem to exist on ICS as well as JB. Older Android OS versions seem unaffected. 

Any ideas?
0
Kristian D. Dimitrov
Telerik team
answered on 23 Jan 2013, 07:37 AM
Hi Marcus,

We have been able to locate the problem inside Cordova's source code and we reported the issue here. For now the solution is to set a reasonable timeout of the request. When the request times out the error handler will be called and you can assume that the server returned status code 401.

Greetings,
Kristian D. Dimitrov
the Telerik team

Share feedback and vote for features on our Feedback Portal.
Want some Kendo UI online training - head over to Pluralsight.
0
Marcus
Top achievements
Rank 1
answered on 23 Jan 2013, 04:14 PM
Thanks!
For now I'm just sending a 403/Forbidden instead of the 401.
Tags
Report a bug
Asked by
Marcus
Top achievements
Rank 1
Answers by
Jan-Dirk
Top achievements
Rank 1
Marcus
Top achievements
Rank 1
Kristian D. Dimitrov
Telerik team
Share this question
or