async/await
// 拿code let getCode = () => { let p = new Promise((resolve, reject) => { $.ajax({ url: './json/code.json', success(res){ resolve(res.code); } }) }) return p; } // 拿数据 let getMsg = (code) => { let p = new Promise((resolve, reject) => { $.ajax({ url: './json/person.json', data: code, success(res){ resolve(res) } }) }) return p } let con = async () => { try{ let code = await getCode() let list = await getMsg(code) console.dir(list.list) }catch(e){ console.log('error', e) } } con()
.