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);
    }
    });

  • 相关阅读:
    Servlet中isCommitted含义及发生的条件
    戏说java web开发中的listener和filter
    Android中以JAR形式封装控件或者类库
    华为总裁在“2012实验室干部与专家座谈会”上的发言!(转)
    C#进行Visio二次开发
    我是谁,从哪里来,将要到哪里去?
    LTE相关网元功能
    走出柏拉图的“洞穴”
    LTE的协议结构
    被联通欠款拖死,被移动集采玩死
  • 原文地址:https://www.cnblogs.com/gduf/p/11944517.html
Copyright © 2011-2022 走看看