Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: $http requests gives -1 status

A node.js server gives "This is a string". (writeHeader, write( string), end).

When performing a $http request, I see that the node.js server is responding and sending the information back.

In Angular I perform the following request:

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;
  }); 
 }
});

Response

{"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":""}

I tried both just sending JSON from node.js or HTML-text. No difference.

like image 930
tm1701 Avatar asked Aug 10 '16 19:08

tm1701


1 Answers

Please consult the official Angular docs for $http. It states the following:

Also, status codes less than -1 are normalized to zero. -1 usually means the request was aborted, e.g. using a config.timeout.

So I guess it is a problem with your backend. Maybe take a look in the developer console to check if the request reaches your server.

like image 180
Sebastian Sebald Avatar answered Oct 04 '22 23:10

Sebastian Sebald