0x00
First, declare a global variable.
var true;
then, make a judgment on the code that slips the penalty for the AJAX request.
if (Control) { $ ('. Get_more '). Click ();};
This place is the function that gets the data and the AJAX request
Get_data:function() { varIle; Control=false;//Let 's start with this function. Global variables set to false in case of repeated requestsLock=true; Target.children (". More_loader_spinner"). CSS (' Display ', ' block '); $ (Settings.trigger). CSS (' Display ', ' none '); if(typeof(Arguments[0]) = = ' Number ') ile = Arguments[0]; Else{ile=Settings.amount; } if(Variables.last >=cur_last) { varPostData =Settings.data; postdata[' Last '] =Variables.last; postdata[' Amount '] =Ile; $.post (settings.address, PostData,function(data) {$ (Settings.trigger). CSS (' Display ', ' block ') methods.add_elements (data) control=true;//after the AJAX request is complete, reset the global variable back to true to make it easier to continue the request. //Note: According to the test here is to be on the lock above, otherwise failed, according to the current observation, is because the above has the condition of judging lock==false, so let's put the global variable on the top of Loca}, Settings.format) Cur_last= Cur_last+6; }}
0x01 above principle :
first declare a global variable set to True, when the sliding time is triggered to determine whether the global variable is true, if true to continue to trigger, or do not trigger,Then, when the
data is fetched, the global variable is set to False before Ajax requests the data, preventing duplicate requests from the data, and then after the Ajax execution, the global variable is changed to True.
this time, you can punish the slide event again, so the loop goes on.
Other complete sample code:
<script type= "Text/javascript" >functiondosearch (keyword) {$ (' #keyword '). val (keyword); GetContent= Get_next_page (1,<?php echo isset ($_get[' cate_id '])? $_get[' cate_id ']: ' 1 ';? >,1); } functionSelect_all () {Get_next_page (1,<?php echo isset ($_get[' cate_id ')? $_get[' cate_id ']: ' 1 ';? >,1); } $(function() {Get_next_page (1); }) varControl=true; $ (window). On ("Scroll",function(){ if(document). ScrollTop () +$ (window). Height () >=$ (document). Height ()) { if(Control) {$ (". Static-box"). HTML ("<p> loading ...</p>"); $ (document). ScrollTop ($ (document). ScrollTop ()+100); Get_next_page (); } } }); Get_next_page=function(getpage,get_cate_id,setempty) {if(get_cate_id) {$ (' #cate_id '). val (get_cate_id)}varcate_id = $ (' #cate_id '). Val (); varb_id = $ (' #b_id '). Val (); varstore_id = $ (' #store_id '). Val (); varKey = $ (' #key '). Val (); varOrder = $ (' #order '). Val (); varKeyword = $ (' #keyword '). Val (); if(getpage) {page= 1; }Else{ varpage = parseint ($ ('. Order_page:last ')). Val ()); Page+ = 1; } varurl = ' index.php?act=mall&op=index&cate_id= ' +cate_id+ ' &store_id= ' +store_id+ ' &b_id= ' +b_id+ ' & key= ' +key+ ' &order= ' +order+ ' &getact=next_page&curpage= ' +page+ ' &keyword= ' +keyword; Control=false; $.ajax ({type:' GET ', Url:url, data:‘‘, DataType:' HTML ', Success:function(data) {if(!data | | data== "" | | data = = "Clear") {Control=false; if(data = = ' Clear '){ $(". Minwrap"). empty (); } $(". Static-box"). HTML ("<p> no more data ...</p>"); SetTimeout (function(){ $(". Static-box"). HTML (""); },1000) return false; } $(". Order_page"). Remove (); if(Setempty = = 1){ $(". Minwrap"). HTML (data); $(' HTML, Body '). Animate ({scrolltop:0}, ' Slow '); }Else{ $(". Minwrap"). append (data); } $("Img.lazy"). Show (). Lazyload ({effect:"FadeIn", Threshold:200 }); Control=true; } }); }</script>
[Ecshop Two development] resolve data duplication caused by the Ajax continuous request of a classified product