当按钮中使用 ng-click 时,我在 IE 上遇到了问题。 我想每当用户单击在 chrome 中工作正常但在 IE11 中工作正常的按钮时从 spring Controller 重新加载数据。 问题是,当页面加载时,数据显示在网页上,当单击“刷新数据”按钮时,它将通过点击在 IE 中不起作用的 spring Controller 来重新加载数据。在 IE 中,当用户单击按钮时,它也会命中 Angular Controller 以及服务方法,但不会命中 Spring Controller 。但是当打开开发人员工具时,它会命中 Spring Controller 。
示例如下: 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;
}
Spring Controller :
@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
}
任何建议都会有帮助。
最佳答案
我检查了您的网址var repUrl = yAppURL+'/myDataToRead/getData.form';
,问题是您没有使用路径来映射 Controller 。您只需使用 /getData
映射您的方法。您需要在 Controller 中使用 @RequestMapping
注释。您可以引用下面的代码:
@RestController
@RequestMapping("/myDataToRead")
关于javascript - 在IE11中测试时无法击中 Spring Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45292749/