欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Jquery ajaxStart()与ajaxStop()方法(实例讲解)

程序员文章站 2023-11-23 19:37:34
jquery中通过ajaxstart()和ajaxstop()两个方法提供了类似的功能。当一个ajax请求启动时,并且没有其他未完成的ajax请求时,将调用ajaxstart()方...

jquery中通过ajaxstart()和ajaxstop()两个方法提供了类似的功能。当一个ajax请求启动时,并且没有其他未完成的ajax请求时,将调用ajaxstart()方法。同样,ajaxstop()方法则是在所有ajax请求都完成时调用。这些方法的参数都是一个函数,这个函数将在事件发生时被调用。

例子

. 代码如下:


<html xmlns="https://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script src="jquery-1.4.2.min.js" type="text/javascript"></script>
      <script type="text/javascript">
        $(document).ready(function(){

         $("#button1").click(function(){
          $.post("default2.x","",function(data){
           $("#x").text(data);
          },"text");
         });
         $("#my").ajaxstart(function(){
             $(this).show();
         }).ajaxstop(function(){
           $(this).hide();
         });

        });
  </script>
</head>
<body>
    <form id="form1" runat="server">

 
    <input id="button1" type="button" value="button"  />
    <p id="my" style=" display:none">
        <img src="loading.gif" />
    </p>
    <p id="x"></p>
    </form>
</body>
</html>