【发布时间】:2017-03-01 22:17:57
【问题描述】:
我有以下 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”
其他一切都经过测试并且工作正常
【问题讨论】:
-
尝试像这样解决错误:console.log("ran into an error :: ", error);该错误可能会帮助您找到问题。
-
dataType: JSON,- 应该是dataType: "JSON", -
您是否忘记在提交功能底部输入
return false;(如果您使用的是提交按钮)? -
@PHPglue,不,我做到了
标签: javascript ajax express routing