JQuery发送请求 不念不忘少年蓝@ 2022-12-24 07:56 76阅读 0赞 //在.HTML文件中引入请求的文件夹位置 <script src="./js/index.js"> </script> //引入css样式1 <link rel="stylesheet" href="###.css"> //引入css样式2 <link rel="stylesheet" href="###.ttc"> .ttc文件 @font-face{ font-family: "MicrosoftYaHei"; src: url("../css/font/msyh.ttc"); font-weight: normal; font-style: normal; } //请求文件夹如下(轮播图案例) /*加载轮播图*/ $(function(){ var baseUrl = "###";//基础路径 $.ajax({ url: baseUrl + '/api/index/banner',//路径 type: 'get',//请求类型 dataType: 'json',//接收参数数据类型 success: function (res) { // console.log(res); var lunboList = res.data; var html = "" lunboList.forEach((item, index) => { html += ` <div class="swiper-slide"> <img src=${ item} alt=""></div> ` }) if (lunboList.length) { $('.banner .swiper-wrapper').html(html);//操作DOM赋值 } } }) }) //$('标签'):操作dom $('标签').on('click', function () { //添加点击事件及方法 window.location.href = '地址' })
还没有评论,来说两句吧...