EricGS
EricGS

Reputation: 1333

cancel current request on new request jqgrid

i have a jqgrid, the grid gets the data on json format from my server.

the grid have some blanck cells and the user can doubleclick them, then an ajax req is send so the server updates a value (current date) and reload the grid, the problem im having is that if i click to fast on 2 or more cells, only the reload for the first cell hapends, if i refresh my page all my data is loaded so i know all request where send ok but apears that the grid reload, can not execute a a new request until the lastone has finished, any idea onn how to solve it?

w i ended up doing: create a var like:

var lastRequestXHR;

on my jqgrid code i add:

    loadBeforeSend: function (xhr) {
        lastRequestXHR = xhr;
    },

and my reload function:

function refreshGrid() {
    if (lastRequestXHR != null) {
        lastRequestXHR.abort();
    }
    jQuery('#scheduledGrid').trigger('reloadGrid');
}

Upvotes: 2

Views: 1636

Answers (1)

Pranav Singh
Pranav Singh

Reputation: 20081

Just push each ajax request to any variable, and in success function abort all request. Some code like below what I intend:

 requests.push(
        $.ajax({
            type: 'post',
            url: '<any url>',
            data: ResponseData,
            success: function(data) {
               for(var i = 0; i < requests.length; i++)
                  requests[i].abort();
            }
        }));

Please note this will cancel all request & its handler on client-side & server request sent will execute but client will not wait for response.

Upvotes: 2

Related Questions