我在前端应用程序中具有以下jQuery代码以发出POST请求:
$("#sendbutton").click(function(){
console.log("Clicked")
console.log(request_data)
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: request_data,
crossDomain:true,
success: function(data) {
alert(data);
},
error: function(jqxhr, status, exception) {
console.log('Exception:', exception);
}
});
});
使用此代码,我看不到服务器收到请求,并且一段时间后客户端显示以下消息:
以及以后的名称:Unchecked runtime.lastError: The message port closed before a response was received.
如果我向Postman发出相同的请求,则服务器会很好地收到该请求,并按预期返回响应。如果有帮助,我通过在服务器上运行request.headers
的服务器上运行成功的请求标头,来显示它的样子(该服务器运行的是装有gunicorn的Flask应用程序):
Content-Type: application/json
User-Agent: PostmanRuntime/7.21.0
Accept: */*
Cache-Control: no-cache
Postman-Token: <token>
Host: localhost:8000
Accept-Encoding: gzip, deflate
Content-Length: 50
Connection: keep-alive