This example describes the way JS and jquery terminate the AJAX request being sent. Share to everyone for your reference, specific as follows:
Core: Invoke the Abort method on the XMLHttpRequest object
The Ajax method of jquery has its own timeout setting parameter:
$.ajax ({type: ' POST ',
URL: ' b.php ',
data: ',
timeout:5000,
success:function () {
}
})
While
1. The data type returned by $.get is XMLHttpRequest, please refer to the manual. ($.post, $.ajax, $.getjson, $.getscript)
2. XMLHttpRequest object has abort () method
You can also manually invoke the Abort method yourself:
<script src = "jquery-1.4.4.js" ></script>
<script>
var xhr = $.ajax ({type: ' POST ',
URL: ' b.php ',
data: ',
success:function () {
alert (' OK ');
}
)
alert (XHR);
Console.log (XHR);
</script>
<button id= "song" >abort</button>
<script>
$ (function () {
$ ("#song"). Click (function () {
alert (' click ');
Xhr.abort ();
})
}
</script>
For the native XHR:
Xmlhttp.open ("POST", "theURL", true);
Xmlhttp.onreadystatechange=function () {
...//After getting the response action
}
xmlhttp.send ();
Set 8 seconds to check to see if the data sent by the XMLHTTP object is responding.
SetTimeout ("Checkrequest ()", "8000");
function Checkrequest () {
/] {
alert (' Response timeout ') was completed on behalf of the request (xmlhttp.readystate!=4)
; Close Request
xmlhttp.close ();
}
I hope this article will help you with Ajax programming.