jquery的then方法

绿地项目中的代码:

  $.ajax({
            url: `https://openapi.italent.cn/OAuth/Token`,
            type: 'post',
            data: `tenant_id=${tenantId}&grant_type=client_credentials&secret=${secret}&app_id=${appID}`,
            contentType: "application/x-www-form-urlencoded",
            success: function(data) { 
                return data 
            },
            error(err) { console.log(err.responseText) }
        }).then(function(data) {
            var HR_token = data;
            $.ajax({
                method: 'GET',
                url: `https://oapi.italent.cn/api/v1/${tenantId}/${ehrUserId}/todo?status=1&pageNum=1&pageSize=4`,
                dataType: 'json',
                contentType: "application/json",
                beforeSend: function(xhr) {
                    xhr.setRequestHeader("Authorization", "Bearer " + HR_token.access_token);
                },
                success: function(res) {
                    sendListData(3, res.data.todos);
                },
                error: function(err) {
                    console.log(err);
                }
            });
        })

以下是百度的用法:

 $.ajax({
    url:"xxxxxx",
    method:"post",
    data:id,
    contentType:"application/json",
}).then(function(res){
    $.ajax({
        url:"",
        method:"post",
        data:res.data.roleIds,
        contentType:"application/json",
        success:function( data ){
            //渲染已选角色下拉框
        }
    })
}) 

 

posted @ 2019-05-21 09:31  smil、梵音  阅读(1753)  评论(0编辑  收藏  举报