nodejs restful api返回错误状态-1在离子angularjs $ http

我的离子angularjs代码,我正在做一个get请求看起来像这样:

.factory('Tasks', function($http) { return { all: function() { $http({ method: 'GET', url: 'http://localhost:3000/hello' }).then(function successCallback(response) { // this callback will be called asynchronously // when the response is available alert(JSON.stringify(response)) }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. alert(JSON.stringify(response)) }); $http({ method: 'GET', url: 'http://localhost:3000/hello' }).then(function successCallback(response) { // this callback will be called asynchronously // when the response is available }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. alert(JSON.stringify(response)) }); } } 

以下哪些警报:

 {"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://localhost:3000/hello","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""} 

我的nodejs api服务器如下所示:

 app.get('/hello', function(req,res){ res.json({hello: "hi"}) }) 

而我的curl:

 curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET localhost:3000/hello 

返回:

 HTTP/1.1 200 OK X-Powered-By: Express content-type: application/json content-length: 14 etag: "-1509679108" Date: Sat, 11 Jun 2016 20:06:29 GMT Connection: keep-alive {"hello":"hi"} 

令人惊讶的是,它与这个testingurl工作正常: http : //jsonplaceholder.typicode.com/posts/1

我需要做些什么来使它工作?