JSON data not parsing in node.js displays undefined in console

JSON data not parsing in node.js displays undefined in console..

Here is HTML code:

var jsonObjects = [{id:1, name:"amit"}];
jQuery.ajax({
      url: 'http://localhost:8081',
      type: "POST",
      data: {"id":"1", "name":"amit"},
      dataType: "json",
     success: function(result) {
    alert("done")
      }
});

Here is Nodejs code:

http.createServer(function (request, response)
{
response.writeHead(200, {"Content-Type":"text/plain"});
var urlObj = JSON.stringify(response.data, true);
console.log(urlObj)
response.end();
}).listen(8081);

Try using GET method Instead of Post. Try this

var jsonObjects = [{id:1, name:"amit"}];

$.ajax({
type: 'GET',
url: 'http://localhost:8081',
data: {
     jsonData: JSON.stringify(jsonObjects)
},
dataType: 'json',
complete: function(validationResponse) {
}
});

The data will be held in the request, not the response as it has come from the client request.

If you are using express to create your http server you will also need to tell it to use the bodyParser middle wear.