Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Angularjs$http.get在Firefox新版本中不起作用_Java_Angularjs_Ajax_Spring_Spring Mvc - Fatal编程技术网

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

Java Angularjs$http.get在Firefox新版本中不起作用,java,angularjs,ajax,spring,spring-mvc,Java,Angularjs,Ajax,Spring,Spring Mvc,Angularjs$http.get在使用Firefox v50及以上版本时不会触发 从下面的Angularjs函数中,始终返回“result is 2”,并且sysout根本不打印,这意味着Spring控制器方法不会每次都被调用。浏览器控制台和服务器端均无错误。有什么解决办法吗 当我点击url www.xxxx.com/api/checkSession时,它会在浏览器中显示2,但不会触发checkSession Spring方法 我通过使用POST解决了这个问题。请检查我下面的答案 Check

Angularjs$http.get在使用Firefox v50及以上版本时不会触发

从下面的Angularjs函数中,始终返回“result is 2”,并且sysout根本不打印,这意味着Spring控制器方法不会每次都被调用。浏览器控制台和服务器端均无错误。有什么解决办法吗

当我点击url www.xxxx.com/api/checkSession时,它会在浏览器中显示2,但不会触发checkSession Spring方法

我通过使用POST解决了这个问题。请检查我下面的答案

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

@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;
}

最后,在AngularJS和Spring控制器方法中,我使用了POST方法而不是GET方法解决了这个问题。现在每次调用Spring方法


但我不知道为什么$http.get方法不调用Spring控制器方法,并且在AngularJS mehood中得到的结果总是2。如果有人知道,请回答。谢谢。

将console.log()添加到javascript中,查看您是否正在使用该函数。@Stephan当我通过浏览器调试时,它显示2&当我点击url www.xxxx.com/api/checkSession时,它在浏览器中显示2。调用该方法时,session属性的值是多少?我想它应该是null,所以只有它执行else块并返回2。但是sysout没有打印,所有其他sysout都在打印您收到警报了吗?另外,当您输入断点并逐步执行服务器端代码时,是否输入了该函数?如果任何一种情况都是正确的,那么您的函数正在被调用,而您的问题并没有说明真正的问题。'is not calling Spring controller method'这是不正确的。它正在调用该方法,否则您将无法得到解析为2…的响应Stephen,sysout不是在该方法内部打印,而是在我使用chrome时打印。我不知道从哪里得到的2可能来自缓存。请在chrome开发工具中关闭缓存,然后重试。如果你仍然得到一个2,那不是缓存,可能是logger配置步骤的问题。我想知道它在chrome中工作,但在最新的firefox浏览器中不工作,因为甚至没有从Spring controller调用该方法。我已经使用sysout检查是否在prodcution中调用了该方法。当使用chrome浏览器时,sysout正在打印,而当我使用最新的firefox版本时,sysout不会打印。现在我改成了POST方法,现在一切都很好。