0

I have used my node.js method getDetails and provide one static id. But data results as object. When I check my node.js method from postman it provide JSON string but AJAX successful data is provide object dont no why??

$.post("/salons/getDetails",
{
    objectId: "561cd801a4b2b6ec1dafba23"
},
function(data)
{
    alert(1);
    alert(data);
});

});

My backend method is 

router.post('/getDetails',function(req,res){
    data=req.body;
    var objectId=data.objectId;
    salon.find({ "_id": objectId }).exec(function(err, data) {
    if (err) throw err;
    res.json(data);
  });
Parkash Kumar
  • 4,710
  • 3
  • 23
  • 39
Altaf Shaikh
  • 41
  • 1
  • 6

2 Answers2

1

Alert only outputs strings, therefore you either use console.log allowing you to see its contents in the console, or use JSON.stringify(data) to convert your JSON object into a string.

André Silva
  • 1,110
  • 8
  • 24
0

You're returning a JSON object. Try putting a console.log(data); instead of alert(data);. Or if you want to keep the alert, try alert(JSON.stringify(data)); and see what it returns.

Nicolae Olariu
  • 2,487
  • 2
  • 18
  • 30