需要按顺序执行ajax请求,之前请求到的数据需要传给下一个函数,一共需要走五步,使用resolve(xxx)来传到下一个promise里,但是到了第3步就开始报错了,求大神指导这个是在node环境下测试的varsuperagent=require('superagent')varp1=function(path){returnnewPromise(function(resolve,reject){superagent.get(path).end(function(err,res){if(err){console.log('err1')}else{if(res.status==200){console.log('step1')resolve(path);}}})});}varp2=function(path){returnnewPromise(function(resolve,reject){superagent.get(path).end(function(err,res){if(err){console.log('err2')}else{if(res.status==200){console.log('step2')resolve(path)}}})});}varp3=function(path){returnnewPromise(function(resolve,reject){superagent.get(path).end(function(err,res){if(err){console.log('err3')}else{if(res.status==200){console.log('step3')resolve()}}})});}varp4=function(path){returnnewPromise(function(resolve,reject){superagent.get(path).end(function(err,res){if(err){console.log('err4')}else{if(res.status==200){console.log('step4')resolve()}}})});}p1("http://www.baidu.com").then(function(val){p2(val)}).then(function(val){p3(val)}).then(function(val){p4(val)})打印结果:step1报错报错step2发现第二步开始值就没有传到第三步里,并且也没有按step1---》step4这个顺序执行求指导
添加回答
举报
0/150
提交
取消