zoukankan      html  css  js  c++  java
  • jQuery中的promise实例

    jQuery中的promise实例

    一、总结

    一句话总结:

    直接在ajax后调用then方法,jquery的ajax会返回promise对象
      <script>
        $(function () {
          $('#btn').on('click', function () {
            $.ajax({
              url: './data.json',
              type: 'get',
              dataType: 'json'
            })
              .then(function (data) {
                console.log(data)
              })
          })
        });
      </script>

    二、jQuery中的promise实例

    博客对应课程的视频位置:

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 
     4 <head>
     5   <meta charset="UTF-8">
     6   <meta name="viewport" content="width=device-width, initial-scale=1.0">
     7   <meta http-equiv="X-UA-Compatible" content="ie=edge">
     8   <title>Document</title>
     9 </head>
    10 
    11 <body>
    12 
    13   <input type="button" value="获取数据" id="btn">
    14 
    15   <script src="./node_modules/jquery/dist/jquery.min.js"></script>
    16 
    17   <script>
    18     $(function () {
    19       $('#btn').on('click', function () {
    20         $.ajax({
    21           url: './data.json',
    22           type: 'get',
    23           dataType: 'json'
    24         })
    25           .then(function (data) {
    26             console.log(data)
    27           })
    28       })
    29     });
    30   </script>
    31 </body>
    32 
    33 </html>
     
  • 相关阅读:
    8.指针小结
    8.指针
    7.数组
    6.结构化程序设计
    python之迭代器
    1.python基础—有这篇文章足够
    python装饰器,细致讲解
    django客户管理系统-使用modelform对HTML标签统一添加样式
    python之md5使用方法
    git干货教程
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/12776377.html
Copyright © 2011-2022 走看看