[英]load content by ajax
我已經創建了這個ajax腳本來加載數據。
$("#submit").click(function(e){
e.preventDefault()
var loading = "<img src='/images/loading.gif' alt='Loading...' />";
var scrolltop=$('#scrollbox').attr('scrollTop');
var scrollheight=$('#scrollbox').attr('scrollHeight');
var windowheight=$('#scrollbox').attr('clientHeight');
// var post = $(this).attr("name") + "=" + $(this).val();
var form_data = $('#search_form').serialize();// + "&" + post ;
var scrolloffset=20;
$('#search').html(loading);
$.post("dosearch.php",form_data,function(newitems) {
$('#content').append(newitems);
});
if(scrolltop>=(scrollheight-(windowheight+scrolloffset))){
$.post("dosearch.php",form_data,function(newitems) {
$('#content').append(newitems);
});
}
});
});
此腳本將采用表格數據並將其序列化,然后將其發布到dosearch.php
之后dosearch將發布我們搜索受限於0.6的數據。 當滾動條到達結果div的底部時,我想獲取更多內容,因此我創建了此函數,該函數將再次獲取表單數據和結果div中的div數量...然后使用此div結果以防萬一限制$ number,6。
function scroll_result(form_data){
var loading = "<img src='/images/loading.gif' alt='Loading...' />";
var scrolltop=$('#scrollbox').attr('scrollTop');
var scrollheight=$('#scrollbox').attr('scrollHeight');
var windowheight=$('#scrollbox').attr('clientHeight');
var scrolloffset=20;
var divnumber = $('#content').children().size();
var form_data = form_data + "&size=" + divnumber;
if(scrolltop>=(scrollheight-(windowheight+scrolloffset)))
{
//fetch new items
$.post('dosearch.php', form_data, function(newitems){
$('#content').append(newitems);
});
}
setTimeout('scroll_result(form_data)', 1500);
}
此功能無法正常工作,我需要一些幫助
提前致謝...
我只是在這里設置了一個示例滾動偵聽應用程序:
您需要監聽滾動scrollbox
滾動事件,
$('#scrollbox').scroll(function(){
console.log('scrolling');
scrolltop=$('#scrollbox').attr('scrollTop');
if(scrolltop>=(scrollheight-(windowheight+scrolloffset))) {
//do whatever you wish to do
}
});
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.