Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery POST: setting Content-Type to be text/plain

Tags:

jquery

I can't figure out why this isn't working. On the server, I have this:

@app.route('/message', methods=['POST'])
def print_post():
    if request.headers['Content-Type'] == 'text/plain':
        logging.warning(request.data)
        return "Text Message: " + request.data
    else:
        logging.warning('didnt work')
        return 'Unsupported Media Type'

I'm sending this request through the browser:

$.ajax({
    type: "POST",
    url: "https://localhost:8090/message",
    data: 'this is a message'
    contentType: 'test/plain'
})

But I keep getting the error Uncaught SyntaxError: Unexpected identifier

What am I doing wrong?

like image 966
Morgan Allen Avatar asked Oct 27 '16 14:10

Morgan Allen


1 Answers

You are missing a comma after your data property in the ajax call, and contentType: 'text/plain'

$.ajax({
    type: "POST",
    url: "https://localhost:8090/message",
    data: 'this is a message', // <-- Put comma here
    contentType: 'text/plain'
})
like image 149
Logan H Avatar answered Sep 29 '22 06:09

Logan H