如果发现AJAX的POST请求没有收到答复,但在网络中显示请求已发送成功,可能有以下几个原因:
服务器端未正确处理POST请求:
跨域请求问题:
请求超时:
以下是一个使用jQuery的AJAX POST请求的代码示例:
$.ajax({
url: "http://example.com/api",
type: "POST",
data: {name: "John", age: 30},
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.log(error);
}
});
以上代码发送了一个POST请求到"http://example.com/api",发送了一个包含"name"和"age"参数的数据对象。如果请求成功,将打印响应数据;如果请求失败,将打印错误信息。
请根据实际情况检查上述原因,并根据需要修改代码以解决问题。