Global event Ajaxstart, ajaxstop not executed in "sharp jquery"

Source: Internet
Author: User

The recent study of "sharp jquery" is indeed a good book, benefiting from it. However, due to technical developments and version updates and other reasons, there are some pits need to tread.

For example: The sixth chapter seven mentions the global event Ajaxstart, Ajaxstop according to the case knocks the result not to be executed.

After reviewing the data, it is found that after the jquery1.9+ version, the AJAX global event must be bound to the document object to be triggered.

Here are the different versions of each version:

<HTML><Head>    <MetaCharSet= "Utf-8">    <style>#loading{position:Absolute;Top:0; Left:0; Right:0;Bottom:0;background:Rgba (0,0,0,.2);Display:None;        }#loading span{position:Absolute;Top:48%; Left:48%;        }    </style></Head><Body>    <DivID= "Loading"><span>Loading ...</span></Div>    <formID= "Demo">        <inputtype= "text"value= "Demo1"name= "Demo1">        <inputtype= "text"value= "Demo2"name= "Demo2">        <inputtype= "text"value= "Demo3"name= "Demo3">        <inputtype= "Submit"value= "Submit"ID= "Submit">    </form></Body></HTML>
<script>    $(function(){        $("#submit"). Click (function(){        //var data = $ ("form"). Serializearray ();            varData = $ ("form"). Serialize (); $.ajax ({type:"Get", URL:"1.php", Data:data, DataType:"JSON",Success:function(data) {Console.log (data); }, Error:function(xhr,error) {console.log (error); }            })        })        //1.9 Previous wording$ ("#loading").Ajaxstart(function(){            $( This). Show (); }). Ajaxstop (function(){            $( This). Hide (); })        //Writing after 1.9+$ (document).Ajaxstart(function(){            $("#loading"). Show (); }). Ajaxstop (function(){            $("#loading"). Hide (); })
//both of these abbreviations
1.9 ago
$ ("#loading"). On ("Ajaxstart ajaxstop", function () {
$ (this). Toggle ();
})
//1.9+ after
        $ (document). On ("ajaxstartajaxstop",function() {            $ ("#loading" ). Toggle ();        })    }) </script>

Global event Ajaxstart, ajaxstop not executed in "sharp jquery"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.