0

I'm sending request through ajax, sending response through Flask.

This is my code

ajax

'''

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

'''

Flask '''

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

If I run this, I can see response header ('hi', 123) in chrome inspection. But NO CONSOLE LOG.

Is there anything wrong with my code?

  • Have you tried out the solution on this page yet? https://stackoverflow.com/questions/11440918/jquery-get-ajax-response-headers – Akib Rhast Jun 02 '20 at 13:37

1 Answers1

0

There's no token response header in your server response, try reading hi header:

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