【问题标题】:unable to hit the spring controller when tested in IE11在 IE11 中测试时无法击中弹簧控制器
【发布时间】:2017-07-25 02:08:25
【问题描述】:

在按钮中使用 ng-click 时,我遇到了 IE 问题。 每当用户单击在 chrome 中运行良好但在 IE11 中运行良好的按钮时,我想从 spring 控制器重新加载数据。 问题是当页面加载数据显示在网页上时,当单击刷新数据按钮时,它将通过点击在 IE 中不起作用的弹簧控制器来重新加载数据。在 IE 中,当用户点击一个按钮时,它会点击角度控制器以及服务方法,但不会点击 spring 控制器。但是当打开开发人员工具时,它会点击 spring 控制器。

以下示例: html代码:

    <div ng-controller="loadingSampleCtrl">
        <button class="btn btn-primary" type="button" ng-click="loadOrRefreshData()">Reload</button>
{{myData.empName}} /* This is printed in chrome as well as in IE with developer tools opened*/
    </div>

js代码:

myApp.controller('loadingSampleCtrl', function ($scope, MyService) {
    $scope.loadData = function () {
    $scope.loading = true;
       MyService.testData().then(
            function (response) {
                alert("response back from spring controllerf");
                if(window.navigator.msSaveOrOpenBlob){
                    $scope.IEBrowser = true;
                    $scope.myData = response;
                    /* $timeout(function() {
                     $scope.pdfName = response;
                     }, 0);*/
                } else {
                    $scope.IEBrowser = false;
                     $scope.myData = response;
                }
            },
            function (errResponse) {
                $rootScope.showError("Internal error" + errResponse);
            });
    }
    $scope.testData();
});

//service call
    _myService.testData = function(){
          alert("service call");//this alert is visible in IE
           var deferred = $q.defer();
        var repUrl = myAppURL+'/myDataToRead/getData.form';
        $http.get(repUrl).then(
                function (response) {
                    deferred.resolve(response.data);
                },
                function(errResponse){

                    deferred.reject(errResponse);
                }
            );
        return deferred.promise;
    }

弹簧控制器:

 @RequestMapping(value = "/getData", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody
    List<String> getMyData(HttpServletRequest request) throws Exception {
        System.out.println("In MyDataController"); //not printed in IE when tested without developer tools
    //logic here
    //return statement
}

任何建议都会有所帮助。

【问题讨论】:

  • 有人遇到过和上面一样的问题????
  • 不明白为什么在 service 中创建的 URL 与为 Spring 控制器声明的 @RequestMapping 不匹配。 URL 应该类似于var repUrl = myAppURL + '/getData';。还要在 IE 开发者工具中检查调用 spring 控制器时记录的错误

标签: javascript java angularjs spring


【解决方案1】:

我检查你的网址var repUrl = yAppURL+'/myDataToRead/getData.form';,我的问题是你不是带有路径的地图控制器。你只是用/getData映射你的方法。您需要在控制器中使用 @RequestMapping 注释。你可以参考下面的代码:

@RestController
@RequestMapping("/myDataToRead")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 2013-06-17
    • 2020-05-26
    相关资源
    最近更新 更多