jQuery+AJAX實現無重新整理下拉載入更多_jquery

來源:互聯網
上載者:User

隨著互連網時代的發展,web前端已經和後台資料掛鈎,作為web前端僅僅不是只切圖寫寫html,css  和簡單js互動。

js  code

$(function() {  var page = 1;  var discount = $('#discount');  var innerHeight = window.innerHeight;  var timer2 = null;  $.ajax({    url: '/lightapp/marketing/verify/apply/list?page=1',    type: 'GET',    dataType: 'json',    timeout: '1000',    cache: 'false',    success: function (data) {        if (data.error_code === 0) {          var arrText = [];          for (var i = 0, t; t = data.list[i++];) {            arrText.push('<div class="consume-whole">');            arrText.push('<h3>' + t.title + '</h3>');            if (t.coupon_type == 1 ) {              arrText.push('<p>金額:¥' + t.amount + '</p>');            } else {              arrText.push('<p>優惠:' + t.amount + '</p>');            }            arrText.push('<p><span class="hx-user">使用者:s賬戶颯颯是是是啊啊12' + t.user_name +'</span>' + '<span>核銷時間:' + t.use_time + '</span></p>');            arrText.push('</div>');          }          discount.html(arrText.join(''));        };        var ajax_getting = false;         $(window).scroll(function() {          clearTimeout(timer2);          timer2 = setTimeout(function() {            var scrollTop = $(document.body).scrollTop();              var scrollHeight = $('body').height();              var windowHeight = innerHeight;            var scrollWhole = Math.max(scrollHeight - scrollTop - windowHeight);            if (scrollWhole < 100) {              if (ajax_getting) {                return false;              } else {                ajax_getting = true;              }              discount.append('<div class="load"><img src="/lightapp/static/zhida-yunying/img/load.gif" width="6%" /></div>');              $('html,body').scrollTop($(window).height() + $(document).height());              page++;              $.ajax({                url: '/lightapp/marketing/verify/apply/list?page=' + page,                type: 'GET',                dataType: 'json',                success: function (data) {                  if (data.error_code === 0) {                    var arrText = [];                    for (var i = 0, t; t = data.list[i++];) {                      arrText.push('<div class="consume-whole"><a href="/lightapp/marketing/verify/page/info?rule_id=' + t.rule_id + '&coupon_id='+ t.coupon_id +'">');                      arrText.push('<h3>' + t.title + '</h3>');                      if (t.coupon_type == 1 ) {                         arrText.push('<p>金額:¥' + t.amount + '</p>');                      } else {                        arrText.push('<p>優惠:' + t.amount + '</p>');                      };                      arrText.push('<p><span class="hx-user">使用者:賬戶颯111111111' + t.user_name +'</span>' + '<span>核銷時間:' + t.use_time + '</span></p>');                      arrText.push('</a></div>');                    }                    discount.append(arrText.join(''));                    $(".load").remove();                  } else {                    $(".load").remove();                    discount.append('<div class="no-data">沒有更多資料。</div>');                    $(window).unbind('scroll');                  };                  ajax_getting = false;                }              });              };            $(".load").remove();          }, 200);        });        if (data.error_code == 156006) {          $('.coupon').html('<div class="error"><h2>出錯啦!</h2><p>原因:未登入</p></div>')        };        if (data.error_code == 156003) {          $('.coupon').html('<div class="error"><h2>出錯啦!</h2><p>原因:許可權不足~請補充</p></div>')        };        if (data.error_code == 156007) {          $('.coupon').html('<div class="error"><h2>出錯啦!</h2><p>原因:服務異常</p></div>')        };        if (data.error_code == 511) {          $('.coupon').html('<div class="error"><h2>出錯啦!</h2><p>原因:帳號未開通直達號</p></div>')        };        if (data.error_code == 520) {          $('.coupon').html('<div class="stays"><span></span><p>暫無核銷記錄</p></div>')        }      },      error: function (data) {      }  })  $(window).bind("orientationchange", function() {    $('.sliders').css('left',$(window).width() / 2 +'px');  })})

以上所述就是本文的全部內容了,希望大家能夠喜歡。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.