2016-12-16 30 views
0

我一直在遇到這個問題,因爲我試圖在設備上運行我的應用程序。 我重新安裝了cordova-whitelist插件。離子應用REST API調用指向一個錯誤的URL

當我嘗試使用ionic serve命令再次從瀏覽器運行應用程序。 該應用程序調用錯誤的API ..

下面是當我嘗試登錄到應用程序時在我的控制檯中的日誌。

POST http://192.168.43.57:8100/auth/login 404 (Not Found)

我的JS代碼宣佈$http網址是從什麼控制檯指向不同。

登錄控制器

$scope.login = function() { 
     var credentials = { 
      username: $scope.loginData.username, 
      password: $scope.loginData.password 
     } 
     $auth.login(credentials).then(function() { 

      $http.get('http://api.mydomain.com/api/login') 
      .success(function(response){ 

       var user = JSON.stringify(response.user); 

       localStorage.setItem('user', user); 

       $rootScope.currentUser = response.user; 

       $ionicHistory.nextViewOptions({ 
        disableBack: true 
       }); 
       $state.go('tabs.download'); 
      }) 
      .error(function(){ 
       var alertPopUp = $ionicPopup.alert({ 
        title: 'Login Failed!', 
        template: 'Invalid credentials' 
       }); 
      }) 
     }); 
    } 

UPDATE:

config.xml中

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<widget id="com.ionicframework.ticappnew343084" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
<name>Test Mobile</name> 
<description> 
    TIC Inspection Report Generator 
</description> 
<author email="[email protected]" href="http://example.com/"> 
    Author Name 
</author> 
<content src="index.html"/> 
<access origin="*"/> 
    <preference name="webviewbounce" value="false"/> 
    <preference name="UIWebViewBounce" value="false"/> 
    <preference name="DisallowOverscroll" value="true"/> 
    <preference name="SplashScreenDelay" value="2000"/> 
    <preference name="FadeSplashScreenDuration" value="2000"/> 
    <preference name="android-minSdkVersion" value="16"/> 
    <preference name="BackupWebStorage" value="none"/> 
<feature name="StatusBar"> 
    <param name="ios-package" onload="true" value="CDVStatusBar"/> 
</feature> 
<plugin name="ionic-plugin-keyboard" spec="~2.2.1"/> 
<allow-navigation href="http://192.168.43.57:8100"/> 
</widget> 
+0

請讓我看看你的config.xml –

回答

0

看完我所有的代碼,我終於找到了解決辦法後.. 似乎我有忘了指定的登錄API URL到我的應用程序配置..

,所以我說這行代碼在我app.js文件

.config(function($stateProvider, $urlRouterProvider, $authProvider){ 
     $authProvider.loginUrl = 'http://api.mydomain.com/api/login' 
}) 

然後改變了網址在我的登錄功能從

$http.get('http://api.mydomain.com/api/login')

$http.get('http://api.mydomain.com/api/user')

這個API檢索用戶通知從服務器獲取。