5

My problem here is that my main page loads some slow asp pages into my divs through jQuery:

$("#content").load("really_slow.asp");

But if I try to go to another page on my site by clicking a link before the ASP page is done, it won't let me go until it's finished loading.

I've tried several ways, but nothing appears to work.... I tried something like this:

var request = $.ajax({
    type: 'GET',
    url: 'really_slow.asp',
    success: function(result){
        $("#content").html(result);
    }
});


$("a").click(function() { 
    request.abort();
});

with no difference...

marcos.borunda
  • 1,486
  • 1
  • 17
  • 34
  • Really? An async XHR request stops the browser from transitioning to another page? – Ates Goral Nov 18 '11 at 18:09
  • possible duplicate of [Kill Ajax requests using JavaScript using jQuery](http://stackoverflow.com/questions/446594/kill-ajax-requests-using-javascript-using-jquery) – jrummell Nov 18 '11 at 18:10
  • I read that question before I posted mine, but it didn't work for me... maybe I need to supply more details... – marcos.borunda Nov 18 '11 at 18:23

2 Answers2

3

You're almost there, just one critical mistake in your code. It should be:

var request = $.ajax({
    type: 'GET',
    url: 'really_slow.asp',
    success: function(result){
        $("#content").html(result);
    }
});


$("a").click(function() { 
    request.abort();
});

The abort() method should be called on the jqXHR object, not the #content div. See: Abort Ajax requests using jQuery

Community
  • 1
  • 1
jli
  • 6,523
  • 2
  • 29
  • 37
1

It's not the jQuery - see this demo: http://jsfiddle.net/H6j4k/1/

So it must be IIS. If you are loading several asp pages at once, it may be that IIS is too busy handling those requests to handle your next one. Aborting the AJAX request will not cause IIS to stop handling the request - it just stops the browser from waiting for the response.

Try adding an external link to your page and navigating to that. Also try opening a new tab in your browser and trying to hit your server. If you are able to navigate to the external page, and especially if you are not able to hit your server, even in a new tab, it's pretty clear that IIS is your bottleneck. If that is the case, it's time to re-architect your code such that you can get by making fewer concurrent requests. Accomplish this either by making requests one at a time, or combining requests so you can get all your data in one shot.

gilly3
  • 87,962
  • 25
  • 144
  • 176