zoukankan      html  css  js  c++  java
  • promiseall 使用一个ajax就可以调全部数据

      <!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- 640px;
      height: 99px;
      margin: 0 auto;
      position: relative;
      }
       
      #tou .heads {
      620px;
      margin: auto;
      overflow: hidden;
      height: 99px;
      }
       
      #logo {
      float: left;
      120px;
      height: 57px;
       
      }
       
      #logo img {
      max- 100%;
      }
       
      #tou #tel {
      position: absolute;
      top: 0;
      left: 325px;
      float: left;
      display: block;
      height: 99px;
      line-height: 99px;
      36%;
      color: #000;
      font-size: 24px;
      font-weight: bold;
       
      text-align: center;
       
      }
       
      #tel span {
      display: inline-block;
      max- 100%;
      }
       
      .xia {
       
      position: absolute;
      top: 21px;
      right: 9px;
      display: inline-block;
      float: right;
       
      }
       
      #wei {
      max- 640px;
      border: 1px solid #ccc;
      margin: 0 auto;
      }
       
      #wei .foots h3 {
      text-align: center;
      }
       
      .slide {
      max- 640px;
      border: 1px solid #ccc;
      margin: 0 auto;
      }
       
      .slide img {
      100%;
      height: 180px;
       
      }
       
      /*----jieshaomokuai-----*/
       
      #jieshao {
      max- 640px;
      margin: 10px auto;
      border: 1px solid #ccc;
      }
       
      #jieshao .jie {
      height: 420px;
      background: red;
      }
       
      #culture {
      max- 640px;
      }
       
      #culture img {
      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="" alt="" 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" alt="">
      </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:"",
      // async:true,
      // success:function(res){
      // $.ajax({
      // type:"get",
      // url:"",
      // async:true
      // });
      // }
      // });
       
      </script>
       
       
  • 相关阅读:
    庆贺自己的软件入围中国软件创新大赛,可惜精英奖没有评上。一个笔记本飞了,哈哈,大奖500万呢!
    VMware vSphere开发(2)配置VMware vSphere Web Services SDK的开发环境
    IPhone 视图切换的的2种方法
    Windows系统加固方案
    我们公司原来C++招聘考试题,题目难度正常,没有稀奇古怪的题,如果答对60分以上,恭喜你基本算一个合格的网络开发工程师了。
    算法分析整数划分
    Java反射机制
    Java类集
    设计包含min函数的栈
    ASP.NET学习之Membership
  • 原文地址:https://www.cnblogs.com/zyyweb/p/9639760.html
Copyright © 2011-2022 走看看