3

I've been working on an Android mobile application which is a cross platform browser based application developed using HTML5, javascript, jQuery and PhoenGap.

Application being a client-server based, we make frequent asynchronous web service calls to fetch data from the server. In this scenario, we are facing problem while fetching data which involves huge amount of data. Here, in this case there are so many database queries that will run at the background to get the data.

We are testing the application using a 2G connection which is resulting in a status 0 error message after few mins.

My question here is, will there be an option for the mobile browser to abort a web service call after few mins before receiving the response?

We are making an ajax call to fetch the data. Sample code for your reference. We have tested with various timeout options but there is no positive result. The same is working fine on a 3G network.

$.ajax({
            type: "POST",
            url: wsUrl,
            contentType: "text/xml",
            dataType: "xml",
            data: soapRequest,
            async: true,
            timeout:300000,
            tryCount:0,
            retryLimit:3,
            success: processSuccess,
            error: processError
    });
Mayur Birari
  • 5,837
  • 8
  • 34
  • 61
Dantuluri
  • 685
  • 1
  • 10
  • 23
  • are you certain that the network connection itself did not fail while waiting for the AJAX response? – Zathrus Writer Dec 05 '12 at 12:13
  • yeah, checking for network availability before making a web service call. and it's working without any issues in 3G. While testing in 2G itself, we are facing this issue. All kinds of server side optimizations and timeouts have been increased. – Dantuluri Dec 06 '12 at 04:51
  • How much data is being processed with this? – Andrew Klatzke Jan 22 '13 at 18:29
  • I hope this will Abort Ajax requests (http://stackoverflow.com/questions/446594/abort-ajax-requests-using-jquery) – Brune Jan 29 '13 at 09:32

1 Answers1

0

yes, you can use a timeout inside ajax call. This is, for instance:

  $.ajax({
            url: syncURL,
            data: {},
            dataType:"jsonp",
            timeout: 10000,
            jsonpCallback: 'jsonpxchange',
            success:function (data) {
                console.log("OK!!");
            },
            error: function(jqXHR, exception) {
                if (jqXHR.status === 0) {
                    alert('No network');
                } else if (jqXHR.status == 404) {
                    alert('Not fount [Error: 400].');
                } else if (jqXHR.status == 500) {
                    alert('[Error: 500].');
                }
                if (exception === 'parsererror') {
                    alert('parser error');
                } else if (exception === 'timeout') {
                    alert('timeout');
                } else if (exception === 'abort') {
                    alert('abort');
                } else {
                    alert('Undefined');
                }
        }
        });

As you see, I use timeout (in msecs), for instance 10secs. and then shot exception===timeout

ManuParra
  • 1,471
  • 6
  • 18
  • 33