只有在IE中打开开发人员工具时才会调用spring控制器

时间:2017-07-24 20:33:44

标签: java angularjs spring-mvc internet-explorer

我想在用户点击按钮时重新加载数据。问题出在IE上。单击该按钮时,在IE中测试时弹簧控制器未被调用,但在chrome中工作正常。我注意到的另一件事是IE中的,当我打开开发人员工具时它正常工作 .Below是我的代码:

html代码:

 <table style="width:100%;height:80%;" ng-controller="loadingSampleCtrl">
<tr> <td><button type="button" ng-click="loadData()">Reload data</button></td></tr>
   <object-reloadable></object-reloadable>
  </table>

js code:

app.directive('objectReloadable', function() {
    var link = function(scope, element, attrs) {
        var currentElement = element;

        scope.$watch('pdfName', function(newValue, oldValue) {
            scope.loading = true;
            if (newValue !== oldValue) {
                scope.loading = false;
                scope.pdfName = newValue;
                var html = '<object style="width: 100%; height: 1200px;overflow-y: hidden; cursor:pointer;" type="application/pdf" data="' + scope.pdfName.filePath + '" ></object>';
                if(scope.pdfName.filePath == "undefined"){
                    scope.loading = true;
                } else {
                    scope.pdfName = newValue;
                    scope.html = '<object style="width: 100%; height: 1200px;overflow-y: hidden; cursor:pointer;" type="application/pdf" data="' + scope.pdfName.filePath + '" ></object>';
                }
                var replacementElement = angular.element(scope.html);
                currentElement.replaceWith(replacementElement);
                currentElement = replacementElement;
            }
        });
    };
    return {
        restrict: 'E',
        scope: false,
        link: link
    };
})

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

//service call
    _fileService.fileRead = function(){
           var deferred = $q.defer();
        var repUrl = myAppURL+'/myFilesToRead/getFileData.form';
        $http.get(repUrl).then(
                function (response) {
                    deferred.resolve(response.data);
                },
                function(errResponse){
                    console.error('Error while fetching RTC Defects detail data' + errResponse);
                    deferred.reject(errResponse);
                }
            );
        return deferred.promise;
    }

弹簧控制器:

 @RequestMapping(value = "/getFileData", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
    public
    @ResponseBody
    List<String> getFileData(HttpServletRequest request) throws Exception {
        System.out.println("In spring controller, getFiledata"); //This is not being invoked from IE
    //logic here
    //return statement
}

使用上面的代码,chrome工作正常,但在IE中测试时,当用户点击Reload data按钮时,它不会调用spring控制器(getFileData(..))来获取最新数据,而是返回相同的旧数据,但当我点击f12并打开开发人员工具时,它正在调用弹簧控制器。我正在使用IE11,控制台中没有显示任何错误。

0 个答案:

没有答案