I have an html page that displays some basic account information and runs a long and poor jQuery AJAX request to get more details. While the Ajax request is running, the user can click the event button onclickto go to a new page with location.assign.
Unfortunately, if the button is pressed before the ajax request completes, nothing will happen until the ajax request completes. This is a problem with the server. I want the user to be able to move right away. FF and Chrome seem to be doing better, but since this is a corporate intranet application, this is actually not an option.
The following code is similar to the page in question:
<html>
<head>
<script src="/js/jquery-1.3.2.min.js" type="text/javascript"> </script>
<script type="text/javascript">
<!--
$(function () {
jQuery.ajax({
type: 'GET',
url: '/long-running-partial-html-ajax-endpoint',
success: function (result) {
$('#detail').html(result); });
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
$('#detail').html('Failed to load additional information:<br />' + textStatus + '<br />' + errorThrown);
}
});
});
</script>
</head>
<body>
<h2>Account Information</h2>
<div>Some basic details here</div>
<div><button onclick="location.assign("/somewhere-else")" type="button">Go somewhere else now</button></div>
<div id="detail">
<img src="/ajax-loading-animation.gif" alt="Loading ..." />
Loading ...
</div>
</body>
</html>
Things I've already tried in the debugger (and not live):
- using simple
anchor, not using a button - using
xhr.abort()beforelocation.assign - put
alertaround location.assignto make sure code runs when expected
Comment:
- IE stops the gif animation as soon as the button is clicked.
- FF / Chrome should automatically abort ajax request when jQuery ajax event fires
error
Has anyone encountered this problem before? Do you have permission that will make navigation more responsive?
source
share