//后台
[HttpPost]
public ActionResult GetNextLazyLoadProduct(int[] productIdList){
var products = _productService.GetProductsByIds(productIdList);
var preparedModel = PrepareProductOverviewModels(products);
return PartialView("_LazyLoadProducts", preparedModel);
}
//前台
var url = "@Url.Action("GetNextLazyLoadProduct")";
$.ajax({
url: url,
type: "POST",
datatype: "json",
contentType: "application/json",
data: JSON.stringify({ productIdList: array }),
error: function () {
},
success: function (data) {
$("#lazyScrollLoading").append(data);
$("#lazyLoadNum").attr("value", nextLazyLoadNum);
}
});
本文介绍了一个使用Ajax实现的懒加载功能,通过后台API获取产品列表并动态加载到前端页面中。该方法通过发送POST请求携带产品ID列表参数,从服务器获取对应的产品数据,并将数据追加到页面指定元素。
4194

被折叠的 条评论
为什么被折叠?



