<!DOCTYPE html> <html> <head> <title>TODO supply a title</title> <meta charset="GBK"> </head> <body> <input type="button" id="btnTest" value="测试"/> <script src="js/jquery-1.11.0.min.js" type="text/javascript"></script> <script> $('#btnTest').click(function() { if (this.ajaxRequest_ != undefined && this.ajaxRequest_.readyState < 4) { alert('wait'); return false; } this.ajaxRequest_ = $.ajax({ type: "POST", url: "homepage/test", success: function(msg) { alert(msg); } }) }); </script> </body> </html>
#php接口返回的消息
public function test() { sleep(5); echo 'success'; }
大神的解决方案:http://ambar.li/blog/2013/04/17/avoid-duplicate-ajax-calls/
我使用了A独占型