jQuery POST:将Content-Type设置为text / plain

Mor*_*len 3 jquery

我不知道为什么这不起作用。在服务器上,我有这个:

@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'
Run Code Online (Sandbox Code Playgroud)

我正在通过浏览器发送此请求:

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

但我不断收到错误 Uncaught SyntaxError: Unexpected identifier

我究竟做错了什么?

Log*_*n H 6

data在ajax调用中找到属性后,您缺少逗号,并且contentType: 'text/plain'

$.ajax({
    type: "POST",
    url: "https://localhost:8090/message",
    data: 'this is a message', // <-- Put comma here
    contentType: 'text/plain'
})
Run Code Online (Sandbox Code Playgroud)