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
我需要做些什么来使它工作?
- 将客户端的图片上传到JSON文件,并通过节点/快捷方式保存到mongo
- 节点/ Angular / Passport / Satellizer基于令牌的Facebook身份validation不返回令牌
- 如何构buildNode / Angular / Socket.io项目?
- POST http:// localhost:3000/404(Not Found)(已更新)
- 如何安装angular-ui-router.js文件,而不是从npm完整的源代码解决scheme?
- 如何包含明确键入Angular 2项目中的文件
- 如何发布nodejs网站
- 通过咕噜开始量angular器
- 量angular器不会暂停debugging