簡體   English   中英

離子應用程序中對簡單節點服務器的 $http 請求拋出“statusText”:“”錯誤

[英]$http request in ionic app to a simple node server throws “statusText”: “” error

我已經刪除了對骨骼的 $http 請求,但它仍然失敗,沒有有用的錯誤消息。 在我的 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;

在我的節點路由中,我有:

router.get('/', function(req, res, next) {
  res.json({test: 'hi from node index.js'})
});

我在 ionic 應用程序中收到的完整錯誤是:

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

我試圖在我的節點服務器中捕獲錯誤並且我收到

TypeError: Cannot read property 'type' of undefined

我在我的節點 app.js 中禁用了 cors。 我試圖與套接字建立連接,但仍然沒有任何運氣。 我正在使用 ionic run 運行我的 ionic 應用程序。

任何幫助將不勝感激。 謝謝。

解決方案:自然,設備有它自己的本地主機,所以當我從我的 ionic 應用程序發送 $http.get 請求時,它不會將它發送到運行節點服務器的同一個本地主機。 解決方案是針對您部署的服務器或本地機器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM