向POST请求发送成功响应

时间:2016-10-20 04:33:48

标签: javascript ajax express routing

我收到了以下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

其他所有内容都经过测试且运行正常

1 个答案:

答案 0 :(得分:1)

首先,dataType应为'json'而不是JSON

然后检查控制台日志中的特定错误。

相关问题