HwangJaeYoung HwangJaeYoung - 5 months ago 16
Ajax Question

Don't read the JSON Object in node.js

I have some problem to get json object...

I send a json object to localhost(node.js server).

When node.js server received the json object, parsed json object has 'undefined
type.

For that reason, I checked the json object but it has not structure problem..

How can I solve this problem?

Thank in advance!

$.ajax({
url: "http://127.0.0.1:62590/saveResource",
type: "post",
dataType: "text",
cache: false,
timeout: 30000,
data: JSON.stringify(jsonObject),
success: function (data) {
............
},
error: function (xhr, textStatus, errorThrown) {
alert(textStatus + ' : ' + errorThrown);
}
});


===========================================================================

app.post('/saveResource', function (request, response) {

var resultObj = request.body;
var object = resultObj.requestInfo;
console.log(typeof(object)); -> 'undefined' type
});


===========================================================================

* node.js server reveceive the following object.


{
"requestInfo": {
"urlInformation": "data",
"methodInformation": "GET",
"bodyInformation": "data",
"headerInformation": []
}
}

Answer

@jeremy-thille already answered the question, but to be more clear just change

dataType: "text"

to

dataType: "json"

And remove the JSON.stringify call....