我有以下 Jquery 脚本它在 Scroll Down 上上传 mysql 数据。问题是有时它请求相同的 url 并三次抓取相同的数据。如何避免获得相同的数据?
$(document).ready(function(){
$(window).scroll(function(){ /* window on scroll run the function using jquery and ajax */
var WindowHeight = $(window).height(); /* get the window height */
if($(window).scrollTop() +1 >= $(document).height() - WindowHeight){ /* check is that user scrolls down to the bottom of the page */
$("#loader").html("<img src='loading_icon.gif' alt='loading'/>"); /* displa the loading content */
var LastDiv = $("#tabsul>li:last"); /* get the last div of the dynamic content using ":last" */
var LastId = $("#tabsul>li:last").attr("id"); /* get the id of the last div */
var offset = $("#tabsul>li").length; //thats the size we have
var ValueToPass = "Id="+ LastId;
$.ajax({ /* post the values using AJAX */
type: "GET",
url: "<?= url('pages/ajax/All/')?>"+offset+"/",
data: ValueToPass,
cache: false,
success: function(html){
$("#loader").html("");
LastDiv.after(html);
}
});
}
});
});