本文實例講述了jquery實現ajax加載超時提示的方法。分享給大家供大家參考,具體如下:
index.php
<!doctype html><html> <head> <meta charset="utf-8"/> <title>加載超時</title> <script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7/jquery.min.js"></script> </head> <body> <script type="text/javascript"> function load(){ $("#tips").html("加載中..."); $.ajax({ async:true, cache:false, timeout:8000, type:"POST", url:"result.php", data:{a:'123'}, error:function(jqXHR, textStatus, errorThrown){ if(textStatus=="timeout"){ $("#tips").html("加載超時,請重試"); }else{ alert(textStatus); } }, success:function(msg){ $("#tips").html(msg); } }); } </script> <input type="button" id="load" onclick="load();" value="點擊加載"/> <div id="tips"></div> </body><html>result.php
<?php//sleep(20);sleep(2);echo $_POST['a'].'test服務器返回結果';
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jquery中Ajax用法總結》、《jQuery form操作技巧匯總》、《jQuery常用插件及用法總結》、《jQuery操作json數據技巧匯總》、《jQuery擴展技巧總結》、《jQuery拖拽特效與技巧總結》、《jQuery表格(table)操作技巧匯總》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答