当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Jquery ajaxStart()与ajaxStop()方法(实例讲解)

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

2019年03月20日  | 移动技术网IT编程  | 我要评论

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>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网