while using an Ajax call I am trying to get data from the back-end
componentDidMount: function () {
$.ajax({
url: 'http://127.0.0.1:3000/ap/test',
dataType: 'json',
success: function (data) {
this.setState(data);
}.bind(this), error: function (xhr, status, err) {
// console.error(this.props.url, status, err.toString());
console.error('failed to view user');
}.bind(this)
});
And here is my Get call in node.js
app.get('/test', function(req, res) { DBs.find({},function(err,data){
if(err){ throw err;}
else {
console.log('GET API CALLED, Data Sent!');
} sendingData = data;}); res.send(sendingData); });
1)API gets called but response isnt sent.('GET API CALLED, Data Sent!')
2)success function doesn't run in the Ajax call resulting in error: 'failed to view user'