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
我需要做些什么来使它工作?
- AngularJS:Karma + Jasmine用_real_后端进行testing
- 在nodejs loopback中安排一个cron作业
- 即使用户重新加载页面,如何保持function运行
- 使用mongolab,nodejs和express提高AngularJS web应用程序的响应时间
- 使用量angular器+ Appium + SauceLabs
- 无法在Node.js res.body中获取$ http.post请求数据
- Angular SPA与API Gateway的任何访问控制允许方法不一致
- 如何build立与Angular.js和Node.js槽服务的连接?
- 是使用Firebase作为AngularJS和NodeJS之间的一个“不好”的想法?