$.ajax()实例

来源:互联网 发布:linux开放端口 编辑:程序博客网 时间:2024/05/20 11:48

ajax瀑布流(不断请求下一页的html)

$(document).ready(function(){var request;var sentIt = true;$(window).on("scroll",function(){     var winHeight = window.innerHeight ? window.innerHeight : $(window).height(); // iphone fixvar closeToBottom = ($(window).scrollTop() + winHeight > $(document).height() - 300);$('#pages').hide();console.log(1)if (closeToBottom) {var nextHref = $("#pages .a1:last-child").attr("href");if(nextHref !="" && nextHref != undefined) {if(sentIt){$.ajax({url: nextHref,cache: false,type: "GET",beforeSend: function(){$('#conPic').append('<div class="onload" style="text-align:center;">正在加载中......</div>');sentIt = false;},success: function(data) {result = $(data).find("#conPic .item");var nextHref2 = $(data).find("#pages .a1:last-child").attr("href");$("#pages").remove();$("#conPic").append(result);// console.log("nextHref2!=nextHref",nextHref2,nextHref)if(nextHref2 !=""&& nextHref2!=nextHref){nextHref = "";$('#conPic').append($(data).find("#pages"));$("#pages .a1:last-child").attr("href", nextHref2);nextHref = nextHref2;}else{nextHref = "";$('#conPic').append('<div class="onload" style="text-align:center;">正在加载中......</div>');}},complete: function(){$('#conPic .onload').remove();setTimeout(function(){sentIt = true}, 500);},error: function(){$("#conPic").text("请求失败了!");setTimeout("$('.page_loading').remove()",1100);setTimeout("$('.page_loading').hide()",1000);}})}}}});})
















原创粉丝点击