加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

promiseall 使用一个ajax就可以调全部数据

发布时间:2020-12-16 03:02:10 所属栏目:百科 来源:网络整理
导读:? !DOCTYPE html ? html ? head ? meta charset=" UTF-8" ? meta name=" viewport" ? content=" width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0" ? meta http-equiv=" X-UA-Compatible" content=" ie=edge,chr
? <!DOCTYPE html>
? <html>
? <head>
? <meta charset="UTF-8">
? <meta name="viewport"
? content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
? <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
? <title></title>
? <link rel="stylesheet" href="js/css/reset.css">
? ?
? <link rel="stylesheet" href="js/swiper.css"/>
? <style>
? ?
? #tou {
? max-width: 640px;
? height: 99px;
? margin: 0 auto;
? position: relative;
? }
? ?
? #tou .heads {
? width: 620px;
? margin: auto;
? overflow: hidden;
? height: 99px;
? }
? ?
? #logo {
? float: left;
? width: 120px;
? height: 57px;
? ?
? }
? ?
? #logo img {
? max-width: 100%;
? }
? ?
? #tou #tel {
? position: absolute;
? top: 0;
? left: 325px;
? float: left;
? display: block;
? height: 99px;
? line-height: 99px;
? width: 36%;
? color: #000;
? font-size: 24px;
? font-weight: bold;
? ?
? text-align: center;
? ?
? }
? ?
? #tel span {
? display: inline-block;
? max-width: 100%;
? }
? ?
? .xia {
? ?
? position: absolute;
? top: 21px;
? right: 9px;
? display: inline-block;
? float: right;
? ?
? }
? ?
? #wei {
? max-width: 640px;
? border: 1px solid #ccc;
? margin: 0 auto;
? }
? ?
? #wei .foots h3 {
? text-align: center;
? }
? ?
? .slide {
? max-width: 640px;
? border: 1px solid #ccc;
? margin: 0 auto;
? }
? ?
? .slide img {
? width: 100%;
? height: 180px;
? ?
? }
? ?
? /*----jieshaomokuai-----*/
? ?
? #jieshao {
? max-width: 640px;
? margin: 10px auto;
? border: 1px solid #ccc;
? }
? ?
? #jieshao .jie {
? height: 420px;
? background: red;
? }
? ?
? #culture {
? max-width: 640px;
? }
? ?
? #culture img {
? width: 100%;
? }
? </style>
? ?
? </head>
? <body>
? <!--头部区域-->
? <div id="tou">
? <!--<iframe src="" width="" height=""></iframe>-->
? </div>
? <!--轮播模块-->
? <div class="slide">
? <div class="swiper-container">
? <div class="swiper-wrapper">
? <!--<img src="" id="img"/>-->
? <!--<div class="swiper-slide">
? <img src="image/c6.jpg"/>
? </div>
? <div class="swiper-slide">
? <img src="image/c8.jpg"/>
? </div>
? <div class="swiper-slide">
? <img src="image/c9.jpg"/>
? </div>-->
? </div>
? <!-- 如果需要分页器 -->
? <div class="swiper-pagination"></div>
? ?
? </div>
? </div>
? <!------------>
? <div id="jieshao">
? <div class="jie">
? <!--<h3>
? qiyejieshao
? </h3>
? <p class="pp">
? ?
? ?
? ?
? </p>-->
? </div>
? </div>
? <!--文化-->
? <!-- <div id="culture">
? <img src="./image/culture.jpg" >
? </div>-->
? ?
? <div id="wei">
? ?
? </div>
? ?
? <script src="js/css/remScale.js"></script>
? <script src="js/css/respond.js"></script>
? <script src="js/jquery.js"></script>
? <script src="js/swiper.js"></script>
? </body>
? </html>
? ?
? <!--<script src="js/ejs.js"></script>
? <script type="text/template" id="temp">
? <% for(var i=0;i<data.length;i++){ %>
? <div class="swiper-slide">
? <img src=<%= data[i].src %>/>
? </div>
? ?
? ?
? <% } %>
? </script>-->
? <script>
? $(function () {
? // ------引入头部和尾部模块
? $("#tou").load("template/heads.html");
? $("#wei").load("template/footer.html");
? // -----
? // 写轮播
? function createPromise(url) {
? return new Promise(function (resolve,reject) {
? $.ajax({
? url,
? dataType: ‘json‘,
? success(arr) {
? resolve(arr);
? },
? error(err) {
? reject(err);
? }
? })
? });
? }
? ?
? // createPromise("http://127.0.0.1:3000/slide").then(function(res){
? // console.log(res)
? // },function(){console.log(请求失败)})
? ?
? Promise.all([
? createPromise("http://127.0.0.1:3000/slide"),
? createPromise("http://127.0.0.1:3000/qiye")
? ]).then(function (res) {
? // res 是一个数组
? ?
? // 第一个轮播
? var str = ""
? for (var i = 0; i < res[0].length; i++) {
? str += "<div class=‘swiper-slide‘>"
? str += "<img src=‘" + res[0][i].src + "‘ />" //<img src="imgse/2.jpg"/> <img src=img/2.jpg/>
? str += "</div>"
? }
? $(".swiper-wrapper").html(str);
? ?
? /////////////////////////////////////////
? var mySwiper = new Swiper(‘.swiper-container‘,{
? direction: ‘horizontal‘,
? loop: true,
? autoplay: 1000,
? observer: true,
? observerParents: true,
? ?
? // 如果需要分页器
? pagination: {
? el: ‘.swiper-pagination‘,
? },
? });
? ///////////////////////////////////////////////
? // ---------轮播结束 企业介绍
? var strs = "";
? strs += "<h3>"
? strs += res[1][0].title
? strs += "</h3>"
? strs += "<p>"
? strs += res[1][0].content
? strs += "</p>"
? $(".jie").html(strs)
? ?
? console.log(res),
? ?
? function () {
? console.log("qingqiushibai")
? }
? })
? ?
? ///////////////////////////////////////////
? // $.ajax({
? // type:"get",
? // url:"http://127.0.0.1:3000/slide",//首页轮播的接口
? // async:true,
? // success:function(res){
? // var str=""
? // for(var i=0;i<res.length;i++){
? // str+="<div class=‘swiper-slide‘>"
? // str+="<img src=‘"+res[i].src+"‘ />" //<img src="imgse/2.jpg"/> <img src=img/2.jpg/>
? // str+="</div>"
? // }
? // $(".swiper-wrapper").html(str)
? // console.log(res)
? //
? //
? //
? // var mySwiper = new Swiper (‘.swiper-container‘,{
? // direction: ‘horizontal‘,
? // loop: true,
? //
? // // 如果需要分页器
? // pagination: {
? // el: ‘.swiper-pagination‘,
? // },
? // })
? // }
? // });
? //// ----
? // $.ajax({
? // type:"get",
? // url:"http://127.0.0.1:3000/qiye",
? // async:true,
? // success:function(res){
? // console.log(res)
? // var str="";
? // str+="<h3>"
? // str+=res[0].title
? // str+="</h3>"
? // str+="<p>"
? // str+=res[0].content
? // str+="</p>"
? // $(".jie").html(str)
? // }
? // });
? ?
? ?
? })
? ?
? // $.ajax({
? // type:"get",
? // url:"",
? // success:function(res){
? // $.ajax({
? // type:"get",
? // async:true
? // });
? // }
? // });
? ?
? </script>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读