1

When I make a request to a web service using the jquery function : $.ajax, it works fine on android, but on iOS, when the response from the server is 4**/5**, the request stay in pending. This is the function which perform a get request :

var ajaxGetJson = function(url) {
        return $.ajax({
            type: "GET",
            url: url,
            dataType: 'json',
            headers: JSON.parse(localStorage.getItem(App.keys.KEY_STORAGE_CREDENTIAL))
        });
    };

So, i tried to fix it with something like that :

var ajaxGetJson = function(url) {
        jqXHR = $.ajax({
            type: "GET",
            url: url,
            dataType: 'json',
            headers: JSON.parse(localStorage.getItem(App.keys.KEY_STORAGE_CREDENTIAL))
        });

        if (jqXHR.state() == 'pending') {
            jqXHR.abort();
        }

        return jqXHR;
    };

It actually works when the response is a 404, but when it should be a 200, the function abort the request and go to the error part.

Why does the request stay in pending only for iOS ? I can't figure it out.

Thanks for helping me, and my apologies for the english.

AVM
  • 592
  • 2
  • 11
  • 25
Véoth
  • 91
  • 7
  • What do you mean by `4**/5**`? – borisano May 07 '15 at 12:12
  • On the possible causes of the issue: http://stackoverflow.com/questions/8724739/jquery-ajax-request-remains-pending, http://stackoverflow.com/questions/16285035/simple-ajax-get-request-is-pending – dekkard May 07 '15 at 12:20
  • I have found using the Charles web proxy tool to watch server interaction between app and server a fantastic tool for debugging. Especially for finding out which end is to blame in situations like yours. http://www.charlesproxy.com/ – Rory McKinnel May 07 '15 at 12:25
  • 5** for server not found and 4** when the ressource isn't found. Ok Rory I will check this. – Véoth May 07 '15 at 12:33
  • Well, a timeout has made my day. Thanks. – Véoth May 07 '15 at 13:03

0 Answers0