开发者社区 问答 正文

jQuery无法在标准promise中使用,求解

使用最新的jQuery,不是说“1.5版本之后,$.ajax()的返回对象实现了CommonJS的Promises/A接口”了吗?

function getJSON(){
    var promise = new Promise(function(resolve,reject){
        jQuery.post('http://127.0.0.1').then(function(data){
            resolve(data)
        })
    })
    return promise
}

jQuery.post('http://127.0.0.1').then(function(){
    return Promise.all([sonthing])
}).then(function(result){
    console.log('result不正常')
})

getJSON().then(function(){
    return Promise.all([sonthing])
}).then(function(result){
    console.log('result正常')
})

希望大神解答,谢谢

展开
收起
a123456678 2016-03-12 10:44:59 1928 分享 版权
1 条回答
写回答
取消 提交回答
  • 1.5之前返回的是xhr对象,省略。

    1.5之后,返回的是deferred对象:

    var promise=$.ajax({

    //

    });
    promise.done(function(){});
    promise.fail(function(){});
    promise.always(function(){});
    1.8之后返回的才是promise对象,注意1.8之前的deferred对象是有then方法的,但不是promise对象。

    2019-07-17 19:00:23
    赞同 展开评论
问答分类:
问答标签:
问答地址: