1.jq3.2.1版本,支持promise写法

2.$ajax()返回的是一个promise对象

3.如果有多个ajax请求 ,可以使用es6中的promise.all方法

例子:

<script src="./jquery-3.2.1.js"></script>
<body>
    <script>
        var a = $.ajax({
            url: './data.txt',
            dataType: 'json',
        })

        var b = $.ajax({
            url:'./data2.txt',
            dataType:'json'
        })

        console.log(a);
        a.then(res=>{
            console.log(res);
        },err=>{
            console.log(err);
        })
        
        Promise.all(
            [a,b]
        ).then(res => {
             let [res1,res2] = res
             console.log(res1);
             console.log(res2);
        }, err => {
            alert('错了')
        })
    </script>
</body>

 

相关文章:

  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-02-08
  • 2021-12-17
  • 2022-02-07
  • 2021-06-27
猜你喜欢
  • 2022-12-23
  • 2021-08-05
  • 2021-11-27
  • 2022-12-23
  • 2021-09-03
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案