【发布时间】:2016-12-17 08:37:17
【问题描述】:
node.js 服务器给出“这是一个字符串”。 (写头,写(字符串),结束)。
执行 $http 请求时,我看到 node.js 服务器正在响应并将信息发回。
在 Angular 中,我执行以下请求:
angular.module('phoneList').
component('phoneList', {
templateUrl: 'phone-list/phone-list.template.html',
controller: function PhoneListController($http) {
var self = this;
$http.get('http://127.0.0.1:8081/echo').then(function(response) {
self.data = response.data;
}, function(err) {
self.error = err;
self.status = response.status;
self.statusText = response.statusText;
});
}
});
回应
{"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url": "http://127.0.0.1:8081/echo","headers":{"Accept":"application/json, 文本/纯文本,/"}},"statusText":""}
我尝试从 node.js 或 HTML-text 发送 JSON。没有不同。
【问题讨论】:
-
"status": -1通常意味着您的后端不可用。可能是 CORSallow-origin问题。控制台有错误吗?