jquery實現ajax加載超時提示的方法
來源:易賢網 閱讀:1382 次 日期:2016-07-29 14:25:31
溫馨提示:易賢網小編為您整理了“jquery實現ajax加載超時提示的方法”,方便廣大網友查閱!

本文實例講述了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加載超時提示的方法
關于我們 | 聯系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權所有:易賢網