我在屏幕上有5条新闻的新闻列表,当用户点击加载更多按钮时 - 我需要再加载5条新闻等。 我有从后端获得的下一页的id(例如2)。
但是当我点击按钮加载更多时出现错误 - lazyload未定义(...)。如何解决此问题? 我不确定 var url =“./”+ {{$ nextPage}};
感谢任何帮助。感谢
<a id="button-more" class="button button--blue load-more" onClick="lazyload.load()"> -> here its an error
var lazyload = lazyload || {};
(function($, lazyload){
var buttonId = "#buttonId",
loadingId = "#loading-div",
newsContainer = ".news-list__list";
lazyload.load = function() {
var url = "./" + {{$nextPage}};
$(buttonId).hide();
$(loadingId).show();
$.ajax({
url: url,
success: function(response) {
if(!response || response.trim() == "NONE") {
$(buttonId).fadeOut();
$(loadingId).text("No more news to load!");
return;
}
appendContests(response);
},
error: function(response) {
$(loadingId).text("Sorry, there was some error with the request. Please refresh the page");
}
});
};
var appendContests = function(response) {
$(buttonId).show();
$(loadingId).hide();
$(response).appendTo($(newsContainer));
};
})(jQuery, lazyload);