- <html>
- <head>
- <mce:script type="text/<a href="http://lib.csdn.net/base/javascript" class='replace_word' title="JavaScript知识库" target='_blank' style='color:#df3434; font-weight:bold;'>JavaScript</a>"><!--
- var currentAjax = null;
- function startAjax(){
- //方法就是将XHR对象指向currentAjax,再调用currentAjax的.abort()来中止请求
- currentAjax = $.ajax({
- type:'POST',
- beforeSend:function(){},
- url:'test.<a href="http://lib.csdn.net/base/php" class='replace_word' title="PHP知识库" target='_blank' style='color:#df3434; font-weight:bold;'>PHP</a>',
- 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>