停止JQuery Ajax请求

来源:互联网 发布:信贷软件 编辑:程序博客网 时间:2024/05/01 14:20
<html><head><mce:script type="text/javascript"><!--var currentAjax = null;function startAjax(){//方法就是将XHR对象指向currentAjax,再调用currentAjax的.abort()来中止请求currentAjax = $.ajax({   type:'POST',   beforeSend:function(){},   url:'test.php',   data:'username=xxx',   dataType:'JSON',   error:function(){alert('error')},   success:function(data){alert(data)}});}function stopAjax(){//如若上一次AJAX请求未完成,则中止请求if(currentAjax) {currentAjax.abort();}}// --></mce:script></head><body><input type="button" value="触发请求" onclick="startAjax()" /><input type="button" value="停止请求" onclick="stopAjax()" /></body></html>

1 0
原创粉丝点击