【问题标题】:Refresh the page with javascript and GET variables使用 javascript 和 GET 变量刷新页面
【发布时间】:2013-06-19 16:15:53
【问题描述】:
<script type="text/javascript">
var email = document.write(localStorage.getItem('email'));
var pass = document.write(localStorage.getItem('pass'));
var url = document.write(document.URL);
document.location.href = url+"?email="+email+"&pass="+pass;
</script>

但是当我进入页面时,我留下了这样的网址: http://example.com/undefined?email=undefined&pass=undefined

没有发生...有人知道这个问题吗?非常感谢!

【问题讨论】:

    标签: javascript get refresh


    【解决方案1】:

    好吧,这里的document.write(…) 怎么样了?你不想打印任何东西:

    var email = localStorage.getItem('email');
    

    但是如果你想打印出测试的值:

    var email = localStorage.getItem('email');
    document.write(email);
    

    (另见console.log(…))

    你应该使用encodeURIComponent(…)转义参数:

    location.href = url + "?email=" + encodeURIComponent(email) +
                    "&pass=" + encodeURIComponent(pass);
    

    你也不应该使用 document.write。有很多更合理的方法可以动态更改您网站上的内容。

    您不应使用 GET 请求发送密码,因为它们会出现在浏览器、代理和服务器日志中。通过不可见的表单使用 POST 请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      相关资源
      最近更新 更多