I have HTML/JS page with a ajax call to a node.js endpoint.
Talking to the endpoint is a success, however my Ajax errors out. Any Ideas?
My JS:
$.ajax({
url: 'http://localhost:1234/test',
type: 'POST',
data: {
"test": "1"
},
success: function (data) {
alert("success");
},
error: function (request, error) {
alert(JSON.stringify(request));
}
});
My Node.js Endpoint:
app.post('/test', function (req, res) {
console.log(req.body.test);
res.setHeader('Content-Type', 'application/json');
res.status(200).send(JSON.stringify({
"status": 200,
"statusText": "succcess"
}));
});
My Node.js Endpoint:
app.post('/test', function (req,res) {
console.log(req.body.test);
res.setHeader('Content-Type', 'application/json');
res.status(200).send(JSON.stringify({
"status":200,
"statusText":"succcess"
}));
});
AJAX Error Message:
{"readyState":0,"status":0,"statusText":"error"}