In the code below, I use the jQuery ajax () function to call a long command. While the ajax function is running, I click on the link to download Firefox (for example), and the ajax call stops.
In fact, he acts as if the call was successful, but he was not, he just stopped.
Why? I want to continue working ...
I saw this problem in Firefox and Chrome. I have not tested other browsers.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function longPoller() {
$.ajax({
type: "GET",
url: '/long-loading-page.php',
dataType: 'json',
async: true,
cache: false,
timeout:50000,
success: function(data){
alert('success');
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert('error');
},
complete: function() {
alert('complete');
}
});
}
$(document).ready(function(){
setTimeout(function(){ longPoller() }, 1000);
});
</script>
</head>
<body>
<a href="http://download.mozilla.org/?product=firefox-3.6.9&os=win&lang=en-US">download Firefox! (clicking this link will stop the jQuery ajax call... why?)</a>
</body>
</html>
source
share