node.js服务器给出“这是一个字符串”。 (writeHeader,write(字符串),结束)。
当执行$ 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, text/plain, /"}},"statusText":""}
我只是尝试从node.js或HTML文本发送JSON。没有不同。
最佳答案
请咨询official Angular docs for $http。它指出以下内容:
Also, status codes less than -1 are normalized to zero. -1 usually means the request was aborted, e.g. using a config.timeout.
所以我想这与您的后端有关。也许在开发者控制台中查看一下请求是否到达您的服务器。
关于angularjs - Angular : $http requests gives -1 status,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38882241/