【问题标题】:Using flask, ajax - get response header value使用烧瓶,ajax - 获取响应头值
【发布时间】:2020-06-03 00:47:22
【问题描述】:

我正在通过 ajax 发送请求, 通过 Flask 发送响应。

这是我的代码

ajax

'''

$.ajax({
    url:'/get',
    type: "post",
    data: {"hi":"hello"},
    success(function(data, textStatus, jqXHR){
        console.log(jqXHR.getResponseHeader('token'));
    })
})

'''

烧瓶 '''

@app.route('/get', methods=['POST'])
def hello():
    data = {'result': 0}
    resp = make_response(data)
    resp.headers['hi'] = 123
    return resp'''

如果我运行它,我可以在 chrome 检查中看到响应标头 ('hi', 123)。但没有控制台日志。

我的代码有什么问题吗?

【问题讨论】:

标签: ajax flask response response-headers jqxhr


【解决方案1】:

您的服务器响应中没有token 响应标头,请尝试阅读hi 标头:

$.ajax({
    url:'/get',
    type: "post",
    data: {"hi":"hello"},
    success(function(data, textStatus, jqXHR){
        // this line: 
        console.log(jqXHR.getResponseHeader('hi'));
    })
})

【讨论】:

    猜你喜欢
    • 2019-07-16
    • 1970-01-01
    • 2018-08-17
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-10
    相关资源
    最近更新 更多