需要按順序執(zhí)行 ajax請(qǐng)求,之前請(qǐng)求到的數(shù)據(jù)需要傳給下一個(gè)函數(shù),一共需要走五步,使用resolve(xxx)來傳到下一個(gè) promise里,但是到了第3步就開始報(bào)錯(cuò)了,求大神指導(dǎo)這個(gè)是在node環(huán)境下測(cè)試的var superagent = require('superagent')var p1 = function (path) { return new Promise(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); } } }) });}var p2 = function (path) { return new Promise(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) } } }) });}var p3 = function (path) { return new Promise(function (resolve, reject) { superagent.get(path).end(function (err, res) { if (err) { console.log('err3') } else { if (res.status == 200) { console.log('step3') resolve() } } }) });}var p4 = function (path) { return new Promise(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)})打印結(jié)果:step1報(bào)錯(cuò)報(bào)錯(cuò)step2發(fā)現(xiàn)第二步開始值就沒有傳到第三步里,并且也沒有按 step1---》step4這個(gè)順序執(zhí)行求指導(dǎo)
關(guān)于promise ajax 使用then順序執(zhí)行的問題
慕勒3428872
2019-03-07 13:15:26