• ajiax请求后台接口数据并拼接展示html


    ajax请求:

      $(document).ready(function() {
                $.ajax({
                    type: "POST",
                    url: url + "appapi/index/indexlist",
                    data: {},
                    dataType: "json",
                    success: function(data) {
                      
                    },
                });
            });
       

    原html代码:

     <div class="bnner">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <a href="#"><img src="images/banner.png"></a>
                    </div>
                    <div class="swiper-slide">
                        <a href="#"><img src="images/banner.png"></a>
                    </div>
                    <div class="swiper-slide">
                        <a href="#"><img src="images/banner.png"></a>
                    </div>
                    <div class="swiper-slide">
                        <a href="#"><img src="images/banner.png"></a>
                    </div>
                </div>
                <div class="swiper-pagination"></div>
            </div>
        </div>
        <script>
            var swiper = new Swiper('.swiper-container', {
                pagination: {
                    el: '.swiper-pagination',
                },
                loop: true,
                autoplay: true,
            });
        </script>

    ajax请求拼接后的代码:

     <script type="text/javascript">
            const url = '/reception/';
            $(document).ready(function() {
                $.ajax({
                    type: "POST",
                    url: url + "appapi/index/index",
                    data: {},
                    dataType: "json",
                    success: function(data) {
                        var banner = data.data.banner;
                        var zuixinruzhu = data.data.zuixinruzhu;
                        var rexiao = data.data.rexiao;
                        var htmlText = '';
                        //banner开始
                        htmlText += '<div class="swiper-container">';
                        htmlText += '<div class="swiper-wrapper">';
                        $.each(banner, function(i, item) {
                            htmlText += '<div class="swiper-slide">' + ' <a href="' + item.bhref + '">';
                            htmlText += '<img src="' + item.images + '">';
                            htmlText += '</a>' + '</div>';
    
                        });
                        htmlText += '</div>';
                        htmlText += '<div class="swiper-pagination"></div>';
                        htmlText += '</div>';
                        $(".bnner").after(htmlText);
                        //swiper配置
                        var swiper = new Swiper('.swiper-container', {
                            pagination: {
                                el: '.swiper-pagination',
                            },
                            loop: true,
                            autoplay: true,
                        });
                        //banner结束
                    },
                });
            });
        </script>

    参考html拼接:https://www.cnblogs.com/xiaobijia/p/5890298.html

  • 相关阅读:
    [多线程学习笔记]条件变量
    [多线程学习笔记]互斥量
    [多线程学习笔记]线程生命周期
    多定时器队列
    双向环形链表
    多目录,多可执行文件的Makfile的编写
    大工匠
    从零开始打造我的计算机系统【运行效果】
    从零开始打造我的计算机系统【交叉汇编器】
    C中的回调函数
  • 原文地址:https://www.cnblogs.com/wangyuxue/p/13413876.html
Copyright © 2020-2023  润新知