zoukankan      html  css  js  c++  java
  • 后端异步接口url

    /wp-common/products.php?term_id=4&page=1


    var currentAjax;
    var total = 0;
    function getAjaxData(term_id, page = 1) {
    currentAjax = $.ajax({
    type: "GET",
    url: "/wp-common/products.php?term_id=" + term_id + "&page=" + page,
    dataType: "json",
    success: function (res) {
    if (res) {
    total = res.total;
    if (total > 0) {
    var products = res.products;
    var subHtml = `
    ${products.map(
    value => `
    <li>
    <a href="${value.url}">
    <div class="img-wrap">
    <img src="${value.image}"
    alt="${value.alt}">
    </div>
    <h4>${value.name}</h4>
    </a>
    </li>`
    ).join('')}`;
    $('.p02-8-s1 .text ul').html(subHtml);
    if (total > 1) {
    $('.mml-pages').mmlpage(page, total, {
    prev: '<i class="fa fa-chevron-left" aria-hidden="true"></i>',
    next: '<i class="fa fa-chevron-right" aria-hidden="true"></i>',
    href: 'javascript:;',
    "click": function (page) {
    $('.p02-8-s1 .text ul').empty().html("<li>loading products...</li>");
    getAjaxData(term_id,page);
    }
    });
    $('.p02-1-s1 .prev').click(function () {
    if (currentAjax) {
    currentAjax.abort();
    }
    $('.p02-8-s1 .text ul').empty().html("<li>loading products...</li>");
    page = page > 1 ? page - 1 : 1;
    getAjaxData(term_id,page);
    });
    $('.p02-1-s1 .next').click(function () {
    if (currentAjax) {
    currentAjax.abort();
    }
    $('.p02-8-s1 .text ul').empty().html("<li>loading products...</li>");
    page = page < total ? page + 1 : total;
    getAjaxData(term_id,page);
    });
    }
    if (!total ) {
    $('.p02-8-s1 .text ul').empty().html("<li>no data</li>");
    }
    }
    }
    }
    });
    }
    var term_id = $('.p02-8-s1 .tab .active').attr('data-term_id');
    if ($(window).width() <= 540) {
    getAjaxData(0, page = 1);
    } else {
    getAjaxData(term_id, page = 1);
    }
    $(window).resize(function () {
    if ($(window).width() <= 540) {
    getAjaxData(0, page = 1);
    } else {
    getAjaxData(term_id, page = 1);
    }
    });

  • 相关阅读:
    第一阶段冲刺(6)--每日立会--个人工作总结
    第一阶段冲刺--每日立会(5)--个人工作总结
    第一阶段冲刺--每日立会(4)--个人工作总结
    第十一周学习记录表
    第一阶段冲刺--每日立会(3)个人工作总结
    第一阶段冲刺--每日立会(2)--个人工作总结
    第一阶段冲刺--每日立会(1)--个人工作总结
    第十周学习记录表
    第九周学习进度表
    输入法
  • 原文地址:https://www.cnblogs.com/gduf/p/11944517.html
Copyright © 2011-2022 走看看