简体   繁体   English

Angularjs $ http.get在Firefox新版本中不起作用

[英]Angularjs $http.get is not working in Firefox new version

Angularjs $http.get is not triggering when using Firefox v50 & above. 使用Firefox v50及更高版本时,不会触发Angularjs $ http.get。

From the below Angularjs function, always returning "result is 2" and sysout is not printing at all that mean Spring controller method is not being called up every time . 从下面的Angularjs函数中,总是返回“结果为2”,并且sysout根本不打印,这意味着不会每次都调用Spring控制器方法。 No error at browser console as well as server side. 在浏览器控制台以及服务器端都没有错误。 Is there any solution for this? 有什么解决办法吗?

When i hit the url www.xxxx.com/api/checkSession it displays 2 in browser but its not triggering CheckSession Spring method. 当我点击网址www.xxxx.com/api/checkSession时,它在浏览器中显示2,但未触发CheckSession Spring方法。

I have resolved by problem using POST. 我已经通过使用POST解决了问题。 Please check my answer below. 请在下面检查我的答案。

CheckSession.js CheckSession.js

this.checkSession = function(){
    var deferred = $q.defer();
    $http.get('/api/checkSession').then(function(response) {
        result = parseInt(response.data);
        if(result==2){
            jAlert("Your Session is Expired!",null,function(){ 
            });
        } else{
            deferred.resolve();
        }
    });
    return deferred.promise;
};

SessionController.java SessionController.java

@RequestMapping(value = "/checkSession", method = RequestMethod.GET)
public @ResponseBody int checkSession(HttpServletRequest httpRequest) {
    int status = 0;
    if (httpRequest.getSession().getAttribute("email") != null) {
        status = 1;
    } else {
         System.out.println("Email"+httpRequest.getSession().getAttribute("email"));
        status = 2;
        if (httpRequest.getSession() != null)
            httpRequest.getSession().invalidate();
    }
    return status;
}

Finally i have resolved the problem by using POST method instead of GET method both in AngularJS & Spring controller method. 最后,我在AngularJS和Spring控制器方法中都使用POST方法而不是GET方法解决了这个问题。 Now Spring method being called up every time. 现在,每次都会调用Spring方法。

But i don't know why $http.get method is not calling Spring controller method and getting result is 2 always in AngularJS mehood. 但是我不知道为什么$ http.get方法不调用Spring控制器方法,并且在AngularJS中总是得到2的结果。 Kindly answer if anybody knows it. 如果有人知道,请回答。 Thanks. 谢谢。

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

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