2

问题

在 php 回显“成功”后,我似乎无法让 javascript 重定向。

我基本上只是想把它放在 javascript 发布我的表单数据的地方,然后将用户重定向到他们的帐户页面。我确实通过 php 完成了这项工作,但我希望能够在登录时保持在同一页面上。

Javascript

 <script>
$(document).ready(function() {
//When the form with id="myform" is submitted...
$("#login_form").submit(function() {
     //Send the serialized data to formProcessor.php.
     $.post("login.php", $("#login_form").serialize(),
     //Take our repsonse, and replace whatever is in the "formResponse"
     //div with it.
    function(data) {
          if(data == "Success"){
          location.href="home";
      }
     }
);
return false;
});
});
</script>
4

2 回答 2

3

document.location您是否window.location使用重定向location.href

window.location = "home.html";

// or 

document.location="home.html"; //Will not work on older IE Version

笔记:

document.location最初是 Gecko 和 Webkit 浏览器允许编辑的只读属性。对于跨浏览器兼容性,请使用window.location它作为读/写属性。

于 2013-07-24T17:44:16.340 回答
2

您可以尝试其中任何一种

方法一:

window.location.replace("home.html");

方法二:

window.location.href = "home.html";

方法三:

$(location).attr('href',"home.html");

希望这会帮助你。

于 2013-07-24T17:50:35.013 回答