Joseph Goh Joseph Goh - 19 days ago 7
MySQL Question

Nodejs + Expressjs + Angularjs Empty Mysql Select Result

I am building an application using angularjs nodejs expressjs and mysql.

Right now i am facing a problem where i am getting empty response from Node while in the node console i saw it successfully retrieve the data from mysql.

angularjs

app.controller('MainCtrl', function($scope, $resource, Map) {
$scope.fetchdata = {};
var Fetchdata = $resource('http://localhost:8080/fetchnote');
Fetchdata.query(function(results) {
$scope.fetchdata = results;
})
console.log(JSON.stringify($scope.fetchdata));
})


nodejs

app.get('/fetchnote', function(req, res) {
connection.query('SELECT * from note', function(err, rows, fields) {
if (!err) {
console.log(rows);
res.json(rows);
} else {
console.log(err);
}
});
});


if i pass
http://localhost:8080/fetchnote
directly to the browser address bar, then it would show all records, same goes to the node console, saw all records, while not in angularjs. No error in javascript console as well, just empty records.

Anyone can give some idea?

HMR HMR
Answer
app.controller('MainCtrl', function($scope, $resource, Map) {
  $scope.fetchdata = {};
  var Fetchdata = $resource('http://localhost:8080/fetchnote');
  Fetchdata.query(function(results) {
      $scope.fetchdata = results;
      console.log(JSON.stringify($scope.fetchdata));
  })
})

In the browser you can press F12 and see the network tab what requests are made (filter for xhr). I prefer Chrome as that has a nice preview of json resonses.