簡體   English   中英

ionic $ http.post在模擬器中失敗,但可在瀏覽器和iPhone中使用

[英]ionic $http.post fails in emulator but works in browser and iPhone

以下代碼可在瀏覽器和iPhone 5s上使用,但不能在iOS模擬器中使用。 我試圖弄清楚它是模擬器還是離子產品。

我已經在Info.plist中設置了NSAppTransportSecurity以便能夠使用http

NSAppTransportSecurity NSAllowsArbitraryLoads和代碼:

accountRepo.register($scope.login.registryCode)
.success(function(data){
    accountRepo.user = data;
    $scope.hideLoading();
    $state.go("setPin");
})
.error(function(err){
    console.log(err);
    $scope.hideLoading();
    alert("Incorrect registry code");
});

和回購

app.factory('accountRepo', function($http) {
   return {
     token: {},
     register: function(registryCode) {
       return $http.post("http://localhost:9501/register",
       {"registryCode": registryCode} );
     },

發生錯誤時,err參數為null。 我在Xcode的輸出中什么也沒得到。 我應該看看其他地方嗎?

有點晚了,但是有人可能會覺得有用。

在進行ionic serveionic run -l時,這是跨源資源共享(CORS)的問題。

您可以通過在ionic.project設置代理來解決此ionic.project

檢查本文以了解更多信息: http : //blog.ionic.io/handling-cors-issues-in-ionic/

暫無
暫無

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

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