Jquery ajax post success函数未被激发?

Jquery ajax post success函数未被激发?,jquery,node.js,Jquery,Node.js,您好,我正在向“/messages/new”发送一个ajax post,其中是console。记录向其发送的数据,然后在客户端上是console。如果成功发送,则记录“已发送”。但是,它不是console.logging发布的 以下是我在客户机上的表单处理: document.getElementsByClassName('contactmeform')[0].addEventListener('submit',function(e){ e.preventDefault(); v

您好,我正在向“/messages/new”发送一个ajax post,其中是console。记录向其发送的数据,然后在客户端上是console。如果成功发送,则记录“已发送”。但是,它不是console.logging发布的

以下是我在客户机上的表单处理:

document.getElementsByClassName('contactmeform')[0].addEventListener('submit',function(e){
    e.preventDefault();
    var data = {
        name: e.target.name.value,
        phone_or_email: e.target.phone_or_email.value,
        message: e.target.message.value
    }


    $.ajax({
      type: "POST",
      url: "/message/new",
      data: data,
      success: function(){
        console.log('postedd')
      }
    });
})
EDIT:console.log正在服务器上运行,但是客户端上没有启动成功回调函数,因此我在浏览器控制台中没有看到“post”。 如何使成功函数启动

app.post('/message/new',function(req,res){
    console.log(req.body);
    return true;
})
然后在ajax上取得成功

$.ajax({
      type: "POST",
      url: "/message/new",
      data: data,
      success: function(response){
        if(response) {
        console.log('postedd')
        }
      }
    });

我在服务器上添加了以下内容:

res.writeHead(200, { 'Content-Type': 'application/json' });
    res.write(JSON.stringify({ status: "OK" }));
    res.end();
因为在dev tools的“我的网络”选项卡中,它说请求仍处于挂起状态,这就解决了它。我在服务器上的完整post处理现在如下所示:

app.post('/message/new',function(req,res){
console.log(req.body.name);
console.log(req.body.phone_or_email);
console.log(req.body.message);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify({ status: "OK" }));
res.end();

})

您的问题是什么?控制台在ajax success或route中不工作?ajax success回调不工作,因此我在浏览器控制台中看不到“已发布”。我编辑了我的问题以澄清@SKJajoriyaTry我的更新答案浏览器开发者工具的“网络”选项卡为请求显示了什么。您应该始终注册失败回调,以便处理/调试错误情况。