Amir A.Eitan Amir A.Eitan - 1 year ago 106
Node.js Question

res.send doesn't print to console

I have an ajax call:

method: "POST",
url: "http://localhost:3000/",
dataType: "json",
data: JSON.stringify({"start" : a.rangeInfos[0].startMarkerId,
"end" : a.rangeInfos[0].endMarkerId}),
contentType: "application/json; charset=utf-8",
success: function(result) {

that is being handled on the server like:'/', function(req, res){
res.send('Got a POST request');

doSomething is defined in the connection.js, as:

doSomething : function(req) {

Everything works great except that the result is not being printed out.
It did print out before I made some changes to the connection and server files, so I'm suspecting it's not a front-end issue, but some weird async issue that keeps escaping me.

Would appreciate help.

Lep Lep
Answer Source

In ajax you declared

dataType: "json"

that means you're expecting data back from the server under json format. So the string Got a POST request && saved To DB cannot be parsed

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download