1

Using Cordova 8.0.0, iOS 12.1.2, trying to make a GET request to my server.

I can make requests successfully to the server, but if for whatever reason it takes longer than 10 seconds then it fails. It DOES work if it takes any amount of time less than that.

This only occurs for me in iOS, the Android build of the app does not show this behaviour and respects the timeout I've set below.

Example snippet:

$.ajax({
            type: "GET",
            url: actionUrl,
            data: data,
            cache: false,
            dataType: "xml",
            timeout: 300000,
            async:   false,
            beforeSend: function (request) {
                request.setRequestHeader("user", settings.userId);
                request.setRequestHeader("sid", settings.sessionKey);
            },
            success: function (results) {
                callback(results);
            },
            error: function (e) {
                if (!surpressError){
                    main.ajaxError(e);
                }

                main.stopLoading();
                if (errorCallback){
                   errorCallback(e);    
                }
            }
        });

Screenshot of request timing

If I make async: true or just take that bit out, the request CAN take longer than 10 seconds to complete but with this legacy app I'd rather not have to change more of it around than I have to to accommodate the switch.

I've also tried adding <preference name="loadUrlTimeoutValue" value="300000" /> to my config.xml, and timeouts of less than 1 minute (30000) but that does not help.

Is there another way I can ensure the timeout is longer than 10 seconds that I have missed?

Armen Michaeli
  • 8,625
  • 8
  • 58
  • 95
Charlie Hermans
  • 128
  • 2
  • 10
  • Never ever use `async:false`. It is a horrible practice and is deprecated. You should be seeing warnings in browser dev tools console about the deprecation. It is especially bad for long requests – charlietfl Dec 20 '18 at 17:15

1 Answers1

0

I managed to work around the issue by removing async: false (thanks charlietfl) and doing:

$.ajax({
    //as above
}).done(function(res) {
    callback(res);
});

This allowed the request to continue, and upon testing with other timeouts now appears to respect that as well. I also needed to move some displaying code on the receiving end of this request to inside the callback.

Ref: jQuery.ajax() method's async option deprecated, what now?

Charlie Hermans
  • 128
  • 2
  • 10