I am passing a JSON object like
[{"name":"SHIFT"},{"name":"CONVERSION"},{"name":"VARIATION"}]
and POST
request is
$.ajax({
url: 'myUrl',
type:'POST',
dataType: "json",
cache: false,
timeout: 5000,
data:json,//passing a json obj
success: function(data, textStatus, jqXHR) { alert("success") },
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
}
});
I am using express within my Node module and below is my node.js code
var express = require('express');
var http = require('http');
var path = require('path');
var app=express();
var app=express.createServer();
app.use(express.bodyParser());
app.use(app.router);
app.post("/",function(request,response) {
console.log(request);
response.header('Access-Control-Allow-Origin', "*");
console.log(request.body)
// response.send(request.body);
});
How do I get the JSON string and parse it in app.post
method ? I tried request.body but it provides me with the following
{"SHIFT":"","CONVERSION":"","VARIATION":""}