2017-06-12 114 views
0

我正在爲小應用程序使用angular.js。在用戶填寫數據並點擊submit按鈕後的註冊頁面中,從控制器調用一個方法,該方法調用API,然後在下一頁面重定向用戶。這在Chrome,Firefox和Microsoft Edge中工作正常,但它在Internet Explorer中不起作用。

這裏是我的signup.html

<form name="userRegForm" 
     ng-submit="userRegForm.$valid && registerUser()"> 
    <md-input-container class="md-block"> 
     <label>Full name</label> 
     <input required 
       ng-model="user.fullName" 
       name="fullName" 
       id="fullName" 
       autocomplete="off" 
       ng-pattern="/^[a-zA-Z ]*$/"> 
     <div ng-messages="userRegForm.fullName.$error"> 
      <div ng-message="required">Full name is required.</div> 
      <div ng-message="pattern">Please enter valid name</div> 
     </div> 
    </md-input-container> 
    <md-input-container class="md-block"> 
     <label>Email</label> 
     <input required name="emailId" ng-model="user.emailId" type="email" autocomplete="off"> 
     <div ng-messages="userRegForm.emailId.$error"> 
      <div ng-message="required">Email is required.</div> 
      <div ng-message="email">Please enter valid Email.</div> 
     </div> 
    </md-input-container> 
    <md-input-container class="md-block"> 
     <label>Password</label> 
     <input required name="password" ng-model="user.password" type="password" autocomplete="off"> 
     <div ng-messages="userRegForm.password.$error"> 
      <div ng-message="required">Password is required.</div> 
     </div> 
    </md-input-container> 
    <section id="non-padding" style="overflow: hidden"> 
     <div class='layout layout--middle'> 
      <div class="layout__item xs-mb1 sm-text-right xs-text-right col-xs-4 sm-5of12 xs-6of12 sm-push7of12 sm-mb0 padding-right-0"> 
       <input placeholder="REGISTER" type="submit" class="button button button--primary" 
         value="SIGN UP"> 
      </div> 
     </div> 
    </section> 
</form> 

這裏是我的controller

$scope.registerUser = function() { 
    apiUrl = "http://example.com/save_data"; 
    var userData = { 
     role: 'CANDIDATE', 
     fullName: $scope.user.fullName, 
     emailId: $scope.user.emailId.toLowerCase(), 
     password: $scope.user.password 
    }; 

    webService.sendPostRequest(apiUrl, userData, 
     function (response) { 
      data = JSON.parse(response.data); 
      if (data.RESPONSE_CODE == 'SUCCESS') { 
       $state.go('restricted.candidate.editProfile', {pageId: ''}, {location: 'replace'}); 
      } else if (data.RESPONSE_CODE == 'WARNING') { 
       alertService.setNotification('Email already exists.', 'warning'); 
       alertService.showNotification(); 
      } else { 
       alertService.setNotification('Something going wrong, Please try again.', 'failure'); 
       alertService.showNotification(); 
      } 
     }, 
     function (err) { 
      alertService.setNotification('Something went wrong, Please try again.', 'failure'); 
      alertService.showNotification(); 
     } 
    ); 
}; 

此代碼工作正常在所有其他瀏覽器,但不僅在Internet Explorer(我有V11時,Windows 10)。

我有谷歌很多關於這個問題,但一些答案是說,取代ng-click="function_name()"直接ng-click="$state.go()"但這不適用於我的情況。

謝謝

+0

使用引發的錯誤或角和路由器版本沒有提到。根據[mcve] – charlietfl

+0

m沒有收到任何錯誤提供演示文稿,重現問題 –

+0

然後使用stateChange錯誤處理程序獲取更多詳細信息。也不清楚請求是否成功 – charlietfl

回答

0

這可能是IE緩存ajax請求的問題。嘗試使用來自服務器的HTTP響應頭禁用緩存,以防止IE緩存Ajax調用。

+0

也見https://stackoverflow.com/questions/16971831/better-way-to-prevent-ie-cache-in-angularjs –

+0

我還沒有使用ajax調用 –

+0

我已經使用$ HTTP sendPostRequest =函數(URL,有效負載的onSuccess,onError的){ 數據= { 'PAYLOAD':JSON.stringify(有效載荷) }; $ HTTP({ 方法: 'POST', 網址:網址, 數據:$ .PARAM(數據), withCredentials:真, 標頭:{ '內容 - 類型':「應用程序/ x-WWW-窗體-urlencoded」 } }) 。然後(功能successCallback(響應){ 的onSuccess(響應); },功能errorCallback(ERR){ 的onError(ERR); }); }; –

0

你可以試着和全球禁用,如:

myModule.config(['$httpProvider', function($httpProvider) { 
    //initialize get if not there 
    if (!$httpProvider.defaults.headers.get) { 
     $httpProvider.defaults.headers.get = {};  
    }  

    // Answer edited to include suggestions from comments 
    // because previous version of code introduced browser-related errors 

    //disable IE ajax request caching 
    $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; 
    // extra 
    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; 
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; 
}]); 
+0

之類的東西全局禁用,結果相同,不起作用 –

相關問題