我正在使用互联网上某处的以下 JQuery 代码在浏览器窗口滚动上加载内容。
var pageIndex = 1;
var pageCount;
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
GetRecords();
}
});
function GetRecords() {
pageIndex++;
if (pageIndex == 2 || pageIndex <= pageCount) {
$("#loader").show();
$.ajax({
type: "POST",
url: "CS.aspx/GetCustomers",
data: '{pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
}
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
var customers = xml.find("Customers");
customers.each(function () {
var customer = $(this);
var table = $("#dvCustomers table").eq(0).clone(true);
$(".name", table).html(customer.find("ContactName").text());
$(".city", table).html(customer.find("City").text());
$(".postal", table).html(customer.find("PostalCode").text());
$(".country", table).html(customer.find("Country").text());
$(".phone", table).html(customer.find("Phone").text());
$(".fax", table).html(customer.find("Fax").text());
$("#dvCustomers").append(table).append("<br />");
});
$("#loader").hide();
}
如您所见,它在响应成功时添加了 HTML 表。但是我有一个 asp.net 用户控件,我想在内容滚动时添加它而不是这个 HTML 表(简而言之,我想从 JQuery 添加一个服务器端控件)。我不能添加用户控件的 HTML 来代替这个 HTML 表,因为它的代码太长太复杂,而且我不太了解 JQuery。我是JQuery初学者概念的初学者。此外,我是后端编程方面的专家。因此,我无法在 JQuery 中编写该业务逻辑。所以任何人请帮助我这样做。