0
我搜索,沒有其他人的問題直接匹配我的。如何從MySQL服務器w/Angular查看RowDataPacket?
我正在使用一個簡單的GET請求來拉取MySQL表,但它只是返回客戶端的一些奇怪的對象。我CONSOLE.LOG在服務器端(行)和它返回:
[ RowDataPacket {
id: 1,
keyword: 'cannabis',
screenName: 'randeemckee',
numFollowers: 1526,
location: 'ÜT: 29.983699,-95.336676',
count: 1,
firstDate: Wed Apr 12 2017 19:19:34 GMT+0000 (UTC),
lastDate: Wed Apr 12 2017 19:19:34 GMT+0000 (UTC) } ]
這裏是我的客戶端代碼:
var dataApp = angular.module('dataApp', [])
.controller('databaseControl', dataControl);
dataControl.$inject = ['$http'];
function dataControl($http){
var dCtrl = this;
dCtrl.getData = function() {
$http.get('/showdata')
.then(function(success){
console.log('Retreived database info!');
console.log(success.data);
}, function(error){
console.log('Error retrieving data: ' + error);
});
};
};
這裏是我的服務器端代碼:
app.get('/showdata', (req, res) => {
connection.query('SELECT * FROM twitterInfo', function(err, rows) {
if (err) {
console.log(err);
res.send(err);
} else {
console.log(rows);
res.send(req.body);
};
});
});
以下是'success.data'在客戶端的樣子:
Object {}
__proto__:Object
constructor:function Object()
hasOwnProperty:function hasOwnProperty()
isPrototypeOf: function isPrototypeOf()
propertyIsEnumerable:function propertyIsEnumerable()
toLocaleString:function toLocaleString()
toString:function toString()
valueOf:function valueOf()
__defineGetter__:function __defineGetter__()
__defineSetter__:function __defineSetter__()
__lookupGetter__:function __lookupGetter__()
__lookupSetter__:function __lookupSetter__()
get __proto__:function __proto__()
set __proto__:function __proto__()
這看起來並不破解的,我只是想從RowDataPacket提取數據並顯示它...