ajaxStart()和ajaxStop()方法

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   color   使用   sp   

使用ajaxSetup()方法設定全域Ajax預設選項

使用ajaxSetup()方法可以設定Ajax請求的一些全域性選項值,設定完成後,後面的Ajax請求將不需要再添加這些選項值,它的調用格式為:

jQuery.ajaxSetup([options])或$.ajaxSetup([options])

可選項options參數為一個對象,通過該對象設定Ajax請求時的全域選項值。

<body>    <div id="divtest">        <div class="title">            <span class="fl">載入一段文字</span>             <span class="fr">                <input id="btnShow" type="button" value="載入" />            </span>        </div>        <ul>           <li id="divload">23322</li>        </ul>    </div>    <script type="text/javascript">        $(function () {            $("#divload").ajaxStart(function(){                $(this).html("正在請求資料...");            });            $("#divload").ajaxStop(function(){                $(this).html("資料請求完成!");            });            $("#btnShow").bind("click", function () {                var $this = $(this);                $.ajax({                    url: "http://www.imooc.com/data/info_f.php",                    dataType: "json",                    success: function (data) {                        $this.attr("disabled", "true");                    $("ul").append("<li>我的名字叫:" + data.name + "</li>");                    $("ul").append("<li>男朋友對我說:" + data.say + "</li>");                    }                });            })        });    </script></body></html>

結果:

  • 23322
  • 我的名字叫:白富美
  • 男朋友對我說:咱們結婚吧!

ajaxStart()和ajaxStop()方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.