I am submitting a form using jquery ajax, I can send the request but cannot recieve a json reponse in success callback. Even though I have set the dataType or content-type to json in ajax and it says Invalid json. Below is the code.
$("#loginForm").submit(function() {
var url = 'localhost:8080/login';
$.ajax({
type: "POST",
url: url,
data: $("#loginForm").serialize(), // serializes the form's elements.
success: function(data)
{
alert(JSON.parse(data));
},
error: function (jqXHR, textStatus, errorThrown)
{
alert(textStatus);
}
});
return false;
});
// serverside node.js
res.set('Content-Type', 'application/json');
res.setHeader("Access-Control-Allow-Origin", "*");
var userName = req.param('userName');
var password = req.param('password');
res.status(404);
res.json({result : "Invalid User"});
how will I recieve this result in success callback.