我无法弄清楚为什么这不起作用。在服务器上,我有这个:
@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'
我通过浏览器发送此请求:
$.ajax({
type: "POST",
url: "https://localhost:8090/message",
data: 'this is a message'
contentType: 'test/plain'
})
但我一直收到错误Uncaught SyntaxError: Unexpected identifier
我做错了什么?
答案 0 :(得分:6)
您在ajax调用中的data
属性后面缺少逗号,contentType: 'text/plain'
$.ajax({
type: "POST",
url: "https://localhost:8090/message",
data: 'this is a message', // <-- Put comma here
contentType: 'text/plain'
})