douye4051
douye4051
2015-06-04 10:24

jscript header重新加载同一页面

已采纳

In my PHP site, I am using script alert for checking invalid username and password. If username and password are wrong, it shows a message box. When I click ok to it, user will be redirected to index.php page. But I want reload same page, like header('Location: '.$_SERVER['PHP_SELF']);.

This is my code :

echo "<script>alert('Invalid Username and Password'); 
location.href='index.php';
</script>";
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douxuqiao6394 douxuqiao6394 6年前

    You can use location.reload()

    echo "<script>alert('Invalid Username and Password'); location.reload();</script>";
    

    the reload() function also has an optional parameter:

    • false - Default. Reloads the current page from the cache.
    • true - Reloads the current page from the server
    点赞 评论 复制链接分享
  • duancaishi1897 duancaishi1897 6年前

    Try this Eval

    echo "<script>alert('Invalid Username and Password'); window.location.href='index.php';</script>";
    
    点赞 评论 复制链接分享