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"