【发布时间】:2017-05-09 18:39:24
【问题描述】:
我是 NodeJs 的新手,我尝试了谷歌搜索,但一无所获。我正在尝试从 API 链接修改 json 数据,但它正在作为原始 json 发送到前端 angularjs。
app.get('/getCustomers', bodyParser.urlencoded({extended: false}), function(req, res){
var url = 'http://www.w3schools.com/angular/customers.php'
var options = {
method: 'GET',
json: true,
url: url
}
request(options, function (err, res, body) {
if (err) {
inspect(err, 'error posting json');
return
}
var headers = res.headers; //working
var statusCode = res.statusCode;
console.log(statusCode); //200
console.log(headers);
console.log(res.body);//prints original data.
res.body.extra='jack is cool';
}).pipe(res);
Angularjs 代码:
$http.get('http://localhost:8080/yo')
.then(function (response)
{
$scope.getApiResponse = response.data;
console.log($scope.getApiResponse); //no modifications
});
非常感谢任何帮助。谢谢
【问题讨论】:
标签: javascript angularjs json node.js