[英]$http request in ionic app to a simple node server throws “statusText”: “” error
I've stripped down an $http request to the bones and it's still failing without a helpful error message.我已经删除了对骨骼的 $http 请求,但它仍然失败,没有有用的错误消息。 Within my Angular factory I have:
在我的 Angular 工厂中,我有:
var url = "http://localhost:3000";
var deferred = $q.defer();
$http.get(url)
.then(function (success) {
deferred.resolve(success)
})
.catch(function (err) {
deferred.reject(err)
})
return deferred.promise;
Inside my node routes I have:在我的节点路由中,我有:
router.get('/', function(req, res, next) {
res.json({test: 'hi from node index.js'})
});
The full error I'm receiving within my ionic app is:我在 ionic 应用程序中收到的完整错误是:
{
"data": null,
"status": -1,
"config": {
"method": "GET",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http://localhost:3000",
"headers": {
"Accept": "application/json, text/plain, */*"
}
},
"statusText": ""
I've tried to catch the error inside my node server and I receive我试图在我的节点服务器中捕获错误并且我收到
TypeError: Cannot read property 'type' of undefined
I've disabled cors within my node app.js.我在我的节点 app.js 中禁用了 cors。 I've tried to make a connection with sockets, but still haven't had any luck.
我试图与套接字建立连接,但仍然没有任何运气。 I'm running my ionic app with ionic run.
我正在使用 ionic run 运行我的 ionic 应用程序。
Any help would be appreciated.任何帮助将不胜感激。 Thanks.
谢谢。
Solution: naturally the device has it's own localhost, so when I'm sending an $http.get request from my ionic app, it's not sending it to the same localhost my node server is running on.解决方案:自然,设备有它自己的本地主机,所以当我从我的 ionic 应用程序发送 $http.get 请求时,它不会将它发送到运行节点服务器的同一个本地主机。 The solution is to target your deployed server or your local machine.
解决方案是针对您部署的服务器或本地机器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.