My get ajax isn't getting the response:
$.get(
'/api/entity',
function(item){
console.log(item); //<-- doesn't show anything at all
}
);
However, when I go to /api/entity
on the browser or check the dev tools, I see the response I'm expecting from the request. Furthermore, when I log XMLHttpRequests, I get XHR finished loading: GET
.
I changed the method of how I get data from mongodb. Instead of sending an array of all the data via callback, I'm now piping the stream directly to res
.
Previous method:
db.entity.find({},function(err,data){
res.end(data);
});
Current method:
db.entity.find({}).cursor({transform:JSON.stringify}).pipe(res);
I need to know how to get the response on ajax.