Ajax call on Jelly Bean not working

8 posts, 0 answers
  1. Marcus
    Marcus avatar
    33 posts
    Member since:
    Jul 2012

    Posted 03 Jan 2013 Link to this post

    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!
















  2. Jan-Dirk
    Jan-Dirk avatar
    327 posts
    Member since:
    Jun 2012

    Posted 03 Jan 2013 Link to this post

    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
  3. Marcus
    Marcus avatar
    33 posts
    Member since:
    Jul 2012

    Posted 04 Jan 2013 Link to this post

    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.
  4. Kristian D. Dimitrov
    Admin
    Kristian D. Dimitrov avatar
    68 posts

    Posted 07 Jan 2013 Link to this post

    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.
  5. Marcus
    Marcus avatar
    33 posts
    Member since:
    Jul 2012

    Posted 07 Jan 2013 Link to this post

    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.
  6. Marcus
    Marcus avatar
    33 posts
    Member since:
    Jul 2012

    Posted 18 Jan 2013 Link to this post

    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?
  7. Kristian D. Dimitrov
    Admin
    Kristian D. Dimitrov avatar
    68 posts

    Posted 23 Jan 2013 Link to this post

    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.
  8. Marcus
    Marcus avatar
    33 posts
    Member since:
    Jul 2012

    Posted 23 Jan 2013 Link to this post

    Thanks!
    For now I'm just sending a 403/Forbidden instead of the 401.
Back to Top