Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.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
Javascript window.location.assign转到错误的URL_Javascript_Jquery - Fatal编程技术网

Javascript window.location.assign转到错误的URL

Javascript window.location.assign转到错误的URL,javascript,jquery,Javascript,Jquery,我有这个代码-index.php,它显示登录屏幕,editor.php是站点管理员 现在,该管理员还有注销链接,其工作方式如下: 点击链接 调用js logout() 它将通过ajax调用logout.php,这将从Cookie中获取身份验证信息 成功处理程序重定向到登录屏幕(index.php)。我也可以重定向到同一个页面,检查认证信息,并将重定向到登录屏幕也 但实际上它是这样工作的: 前三个是相同的 成功处理程序通过do window.location.assign('index.ph

我有这个代码-index.php,它显示登录屏幕,editor.php是站点管理员

现在,该管理员还有注销链接,其工作方式如下:

  • 点击链接
  • 调用js logout()
  • 它将通过ajax调用logout.php,这将从Cookie中获取身份验证信息
  • 成功处理程序重定向到登录屏幕(index.php)。我也可以重定向到同一个页面,检查认证信息,并将重定向到登录屏幕也
但实际上它是这样工作的:

  • 前三个是相同的
  • 成功处理程序通过do window.location.assign('index.php')重定向到同一页面(editor.php-Chrome控制台显示“导航到…editor.php”)。php不知道用户不再经过身份验证,仍然显示管理页面。刷新页面时,editor.php会正确重定向到index.php
我知道处理注销程序有点奇怪,请不要批评设计:)我不想知道正确的方法,但我明白:

  • 为什么浏览器决定location.assign('index.php')应该 实际上是'editor.php'(重定向缓存?登录后有redirect index.php->editor.php)。我也尝试了完整的网址
  • 为什么editor.php实际上没有重新加载自身(缓存?)
  • html:


    请注意,如果我将location.assign替换为location.reload,它将正常工作。

    为什么不尝试window.location.href='/logout.php'您的意思是
    window.location.href='/index.php'
    ?同样也尝试过了。刚刚通过logout()中的window.location.href='/index.php',并对ajax调用进行注释检查它是否正常工作?
    <a href="#" onclick="logout(); return false;">logout</a>
    
    function logout() {
        $.ajax({
            type : "POST",
            url : "logout.php",
            // simplified success handler
            success : function(msg) {
                // will eventually redirect to right place
                window.location.assign('index.php');
                //window.location.reload(); // NOTE this instead of assign works correctly
            }
        });
    }