简体   繁体   English

$ state.go在Internet Explorer中不起作用

[英]$state.go not working in Internet explorer

I am using angular.js for small app. 我正在为小型应用程序使用angular.js。 in signup page after user user fill the data and click on submit button one method is called from controller that make API call and then redirect user on next page. 用户填写数据并单击submit按钮后,在注册页面中,从控制器调用一种方法,该方法将调用API,然后在下一页上重定向用户。 this is working fine in Chrome, Firefox and Microsoft Edge but it's not working in Internet Explorer. 在Chrome,Firefox和Microsoft Edge中可以正常工作,但在Internet Explorer中无法正常工作。

Here is my signup.html 这是我的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>

Here is my controller 这是我的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();
        }
    );
};

This code is working fine in all other browser but not only in Internet explorer (i have v11, Windows 10). 这段代码在所有其他浏览器上都可以正常运行,但不仅在Internet Explorer(我有v11,Windows 10)中也可以。

i have google a lot on this issue but some answer are saying that replace ng-click="function_name()" to direct ng-click="$state.go()" but this won't work in my case. 我在这个问题上有很多google信息,但是有人回答说替换ng-click="function_name()"来指示ng-click="$state.go()"但是在我的情况下这行不通。

Thanks 谢谢

You can try and disable globally like: 您可以尝试全局禁用,例如:

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';
}]);

It could be a issue with IE caching ajax requests. IE缓存ajax请求可能是一个问题。 Try disabling caching using HTTP response headers from the server so that it will prevent IE from caching Ajax calls. 尝试从服务器使用HTTP响应标头禁用缓存,以防止IE缓存Ajax调用。

res.header("Cache-Control", "no-cache, no-store, must-revalidate");
res.header("Pragma", "no-cache");
res.header("Expires",0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM