Mein Kunde macht einen Ajax-AufrufNodeJS Wie Daten in Server erhalten, von Jquery Ajax-Aufruf via POST gesendet
{{
function callNode(){
console.log("I am called");
var data = {"emailId":"[email protected]"};
$.ajax({
type: 'POST',
data: JSON.stringify(data),
/* data: {
blob: {wob:"1",job:"2", ar:[1,2,{a:'b'}]}
},*/
contentType: "application/javascript",
//contentType: "application/x-www-form-urlencoded",
dataType:'json',
url: 'http://localhost:3000/notification',
success: function(data) {
console.log('success');
console.log(JSON.stringify(data));
},
error: function(error) {
console.log("some error in fetching the notifications");
}
});
}
}}
ich in der Lage bin Anfrage in meinem app.js zu bekommen, aber nicht in der Lage das bekommen Daten, die ich bin vorbei ich versuchte
{{
app.post('/notification', function(req, res) {
JSON.stringify(req.params);
/*
var body;
req.on('data', function(chunk) {
console.log("Received body data:");
body += chunk;
});
// the end event tells you that you have entire body
/*req.on('end', function() {
try {
var data = JSON.parse(body);
colnosole.log(data);
} catch (er) {
// uh oh! bad json!
res.statusCode = 400;
return res.end('error: ' + er.message);
}
}
*/
}}
Sache zu suchen, aber nichts funktioniert wird sein kommen nicht in irgendwelchen Ereignissen von Anfrage und Antwort (wie ich viele Menschen gesehen haben, unter Verwendung der Daten zu holen.
Helfen Sie mir zu wissen, was falsch ist hier sein erstes Mal Ajax am Knoten
Es funktionierte dank V31. Nur die von dir erwähnten Änderungen sind nötig um es laufen zu lassen :) –