我收到了以下ajax电话:
function sendRequest(quote, author){
$.ajax({
type: "POST",
url: window.location.pathname,
data: {quote: quote, author: author},
dataType: JSON,
success: function(){console.log("Data sent!");},
error: function(error){console.log("ran into an error")}
});
}
这是我的服务器(使用快递)处理邮件请求,
app.post("/", function(req, res){res.status(200).end("Success!")});
但是,控制台不会打印“Data Sent
”。而是打印“ran into an error
”
其他所有内容都经过测试且运行正常
答案 0 :(得分:1)
首先,dataType应为'json'
而不是JSON
然后检查控制台日志中的特定错误。