user2237814 user2237814 - 6 months ago 17
Javascript Question

Chrome is only queuing 2 ajax requests at a time

I have a click event which adds an item to a user's cart server side and client side asynchronously. This works fine in all browsers until the user clicks more than twice in Chrome before the ajax request completes. In the network console in IE and Firefox, I can see the requests being properly queued, but Chrome only queues two at a time and ignores everything else. Even using a success event doesn't help because it fires even if Chrome ignored it.

$(div).on('click',function () {
$.ajax('script.php')
.success(function() {
dosomething();
});
});


If you fire this event 5 times in quick secession, script.php will be called twice while dosomething() will be called 5 times.

Is there a way to get Chrome to handle more than two requests or at least call some function as many times as the actual ajax is loaded?

Answer

Changing the code to

$(div).on('click',function () {
    $.ajax({url: 'script.php',cache: false})
    .success(function() {
        dosomething();
    });
});

Seems to have worked. Feel free to enlighten me on why Chrome would cache an ajax request for 1 second.

Comments