dstjh46606 2016-10-27 07:18
浏览 39

lazyload未定义(...)

I have news-list with 5 news on the screen and when user clicks on Load more button - i need to load 5 more news etc. I have id of the next page gotten from back-end (ex. 2).

But when i click on the button Load more i got an error - lazyload is not defined (…). How to fix this? And i'm not sure about var url = "./" + {{$nextPage}};

Any help is appreciated. Thanks

<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);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!