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()

.

posted @ 2019-11-19 14:36  徐林俊  阅读(93)  评论(0编辑  收藏  举报