angularjs - Angular : $http requests gives -1 status

标签 angularjs angularjs-http

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/

相关文章:

angularjs - 与 leaflet.heat 一起使用时,传单 CircleMarker 事件不起作用

AngularJS 没有检测到 Access-Control-Allow-Origin header ?

javascript - aspx 页面中的 Web 方法未执行

angularjs - 是否可以使用 Angular 的 $http 服务指定参数顺序?

javascript - Angular $scope 在我的函数之外不可用

javascript - 如何展平对象的嵌套嵌套数组

javascript - 使用 Jasmine 在 AngularJS 中测试去抖函数永远不会调用该函数

angularjs - Angular UI-Grid 无法获取要显示的数据

javascript - 为什么通过 JavaScript 从浏览器向本地主机发出的请求不会被阻止?

angularjs - 使用带有 angular 的 $q 服务