我正在使用这个jQuery脚本来显示搜索结果。一切工作正常,但是当搜索结果有多个页面,并且我通过分页浏览页面时,每个页面加载速度都会逐渐变慢。通常情况下,首先加载10页我很快就会加载,但接下来会避免加载延迟。整个网站被冻结一会儿(也是装载机图像),但浏览器还没有。应该是什么问题?使用jQuery脚本页面加载正在逐渐变慢
function editResults(def) {
$('.searchResults').html('<p class=\'loader\'><img src=\'images/loader.gif\' /></p>');
var url = def;
var url = url + "&categories=";
// Parse Categories
$('input[name=chCat[]]').each(function() {
if (this.checked == true) {
url = url + this.value + ",";
}
});
url = url + "&sizes=";
// Parse Sizes
$('input[name=chSize[]]').each(function() {
if (this.checked == true) {
url = url + this.value + ",";
}
});
url = url + "&prices=";
// Parse Prices
$('input[name=chPrice[]]').each(function() {
if (this.checked == true) {
url = url + this.value + ",";
}
});
$('.searchResults').load('results.php'+url);
$('.pageLinks').live("click", function() {
var page = this.title;
editResults("?page="+page);
});
}
$(document).ready(function(){
editResults("?page=1");
// Check All Categories
$('input[name=chCat[0]]').click(function() {
check_status = $('input[name=chCat[0]]').attr("checked");
$('input[name=chCat[]]').each(function() {
this.checked = check_status;
});
});
// Check All Sizes
$('input[name=chSize[0]]').click(function() {
check_status = $('input[name=chSize[0]]').attr("checked");
$('input[name=chSize[]]').each(function() {
this.checked = check_status;
});
});
// Edit Results
$('.checkbox').change(function() {
editResults("?page=1");
});
// Change Type
$(".sort").change(function() {
editResults("?page=1&sort="+$(this).val());
});
});
是服务器的响应可能越来越慢回来?通常情况下,获取第x页的速度随着x的增加而变慢,因为数据库中必须遍历更多的记录。您可以通过在服务器端页面上打印计时结果或使用[** Fiddler **](http://www.telerik.com/fiddler)等工具捕获计时结果来验证此情况。 – mellamokb
是的,你是对的。感谢您的解释,但是您的意思是在我的服务器端页面上打印计时结果的意思是什么? – user2406937
注意:'.live()'自从jQuery 1.7开始被弃用,并且在1.9中被删除。建议您切换到较新的'.on()' –