在做东西时发现需要获取动态的地址来实现下滑页面。所以总结之用,高手勿喷。
var page=2;
var url=document.URL; //获取当前页面地址的js
var m=url.lastIndexOf("/");//到最后一个"/"符号的数目
var base=url.substr(0,m);//到最后一个"/"符号之前的地址内容
//比如http://localhost:8080/html
if(scrollTop+windowHeight-scrollHeight<=50){
setTimeout(function(){
page+=1;
finished=0;
},1000);
$.ajax({
type:"get",
url:base+"/list"+page+".html",
//当page=2时即http://localhost:8080/html/list2.html 依次调取list3.html,list4.html等
dataType:'html',
data:{},
success:function(result){
var backHtml=$(result).find("#plush-ul li")//选取所需页面的部分
$("#hide").html(backHtml);//存储到本页面的空div
$('#hide').hide();//另div隐藏
$("#plush-ul").append(backHtml);//将获取数据到的加到本页数据之后
$('#plush-ul').show();//将数据显示出来
},
});
finished=1;
}