我正在使用angularjs应用程序。我在我的主页上有一个按钮,当用户点击按钮时,它必须击中控制器,并从后端获取数据并显示在浏览器上。一切工作正常在铬和Firefox但不能在IE中工作。试图很难找到一个替代解决方案来解决,但没有运气,任何建议都会有所帮助。替代按钮ng-click in angularjs
HTML: 登录
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"); //printed only when navigated through chrome
//logic here
//return statement
}
PS:当同上面的代码在IE11中执行,这是不打春控制器,但能正常工作是Chrome和Safari。什么可能是实现与angularjs中的按钮相同的功能的替代方法,并且可以在IE和Chrome中使用。
--EDITED-- JS控制器:
myApp.controller('myController', function ($scope, MyService) {
$scope.btnAdminDetails= function() {
alert("In btnAdminDetails, js controller"); //this is called both in IE11 and chrome
console.log("In controller");
MyService.retrieveData().then(
function (response) {
alert("response back from spring controller");
if(window.navigator.msSaveOrOpenBlob){
$scope.IEBrowser = true;
$scope.myData = response;
} else {
$scope.IEBrowser = false;
$scope.myData = response;
}
},
function (errResponse) {
$rootScope.showError("Internal error" + errResponse);
});
}
$scope.btnAdminDetails();
});
//service code
_myService.retrieveData= function(){
alert("service call");//called when tested from both IE and chrome, but issue is from IE the java controller is not getting called from here..
console.log("In Angular Service above $q.defer ");
var deferred = $q.defer();
console.log("In Angular Service below $q.defer");
var randomh=Math.random();
var repUrl = myAppURL+'/myControllerr/getData.form?x='+randomh+"";
$http.get(repUrl).then(
function (response) {
deferred.resolve(response.data);
},
function(errResponse){
deferred.reject(errResponse);
}
);
return deferred.promise;
}
I have added Math.random to the request URL in the service call.
在IE11,当我点击该按钮仅示出了在控制器警报btnAdminDetail, js controller
,其他警报报表或的console.log陈述未打印。
你能告诉我这是点击按钮,btnAdminDetails函数正在运行吗?或不? –
是的它也在运行并调用角度控制器,问题是它没有打到弹簧控制器。 – user7833845
请向我们展示您的MyService代码。 –