Software Archive
Read-only legacy content
17061 Discussions

Trouble with xhr. Sometimes not firing

Eirik_N_
Beginner
393 Views

Hello

I have problems with ajax requests sometimes not firing when running my application on android and ios. It is most prevailent on android.
I get this the most when i am testing request against our test servers, but we also have problems on a customer server. On other customer servers this problem just happens occasionally.

The requests does not return any error, and if i don't set a timeout on the request, the app is stalled forever(due to the blockui-method which is used when the user has to wait for server requests). I have set a global timeout to 2 minutes
    $.ajaxSetup({
        timeout: 120000 //Time in milliseconds
    });

The requests are jquery ajax request and look like this:
 

Transport.Data.Database.getTransportForWeek = function (weekno, year, callback)
{
    'use strict';
    var account = Core.Data.LocalStorage.Account.get();
    $.ajax({ url: Core.ServiceURL + 'Transport/GetTransportForWeek',
            cache: false,
            type: 'GET',
            dataType: 'json',
            data: { weekno: weekno, year: year, employeeid: account.EmployeeId },
            success: function (data) {
                //do stuff
            },
            error: function (x, y, z) {
                //catch error
            }
        });
};

Most times the requests works fine, and sometimes i get this stalling. I dont get this error when running the app as a website in chrome. The service which i am calling is used by other programs in my company and none of these programs get this problem.
Most times I get the error myself is when i have put the phone down for a bit and then the first request will fail. 
It has to be something when the code is built as a hybrid mobile app that is wrong.
I am using Intel XDK to get the cordova package which is then uploaded to phonegap where the apps are built.

I have tried phonegap cli6.2.0 and cli6.5.0. The <access origin="*"/> in the config.xml

Do you have any tips to what might be wrong here?
 

Best regards
Eirik

0 Kudos
3 Replies
PaulF_IntelCorp
Employee
393 Views

See this FAQ, it might have some information that could help > https://software.intel.com/en-us/xdk/faqs/app-designer#ajax-jquery-one-fail < In particular, the version of jQuery you are using may be part of the problem. In most cases it is recommended that you use jQuery 2 or 3, but you may have to experiment to determine which works best for your app and, especially, as a function of the version of Cordova you are building against and the version of Android and/or iOS that is running on the target device.

0 Kudos
Eirik_N_
Beginner
393 Views

Thanks for the reply.

I updated jquery from 1.10.2 to 2.2.4, but there was no change. Sometimes the requests does not fire and there is no error code. I have used wireshark to check the traffic on the server, and these requests does not arrive at the server.

Eirik
 

0 Kudos
Eirik_N_
Beginner
393 Views

I managed to get my code running as a site on chrome on my phone since i updated the jquery. When I connect remote devices in chrome on my pc and look at the network tab, it says that the requests are stalled. This is probably not a intel xdk problem then, but might have to do with the server? 

0 Kudos
Reply