使用最新的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正常')
})
希望大神解答,谢谢
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
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对象。