如何获取post请求返回response的值?

图片描述

    getUser: function (sessionId) {
        fetch('/account_auth_admin_new_test/personal-api.accessLogin', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                sessionId: sessionId,
                enterpriseCode: "SUNEEE",
                clientIp: "127.0.0.1",
                encryptCode:"1234567899876543",
                appCode: "XIANGPU"
            })
        }).then(function(res){
            console.log(res.json())
        }).then(function(err){
            console.log('错误',err)
        })
    }

fetch模块:https://github.com/github/fetch

阅读 8.1k
1 个回答
getUser: function (sessionId) {
    fetch('/account_auth_admin_new_test/personal-api.accessLogin', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            sessionId: sessionId,
            enterpriseCode: "SUNEEE",
            clientIp: "127.0.0.1",
            encryptCode:"1234567899876543",
            appCode: "XIANGPU"
        })
    }).then(function(res){
        return res.json()
    }).then(function(json) {
        console.log('parsed json', json)
    }).catch(function(ex) {
        console.log('parsing failed', ex)
    }).then(function(err){
        console.log('错误',err)
    })
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题