我只是注意到encodeURI
使用with的这种行为form
。我使用编码了一个网址encodeURI
。
<html>
<head>
</head>
<body>
<form id="form">
</form>
<button id="button">Click Me to submit form</button>
</body>
<script>
var button = document.getElementById("button");
button.onclick = function() {
var form = document.getElementById("form");
var url = "b.html?name=" + encodeURIComponent("First Name");
form.action = url;
form.method = "post";
form.submit();
}
</script>
</html>
提交表单后,我在浏览器地址栏中没有得到期望的结果。我期待着
b.html?name=First%20Name
我得到的是-
b.html?name=First Name
有人可以告诉我为什么会这样吗?
笔记-
我仅在firefox中遇到此问题(我正在使用24.0版)。在chrome上,其行为符合预期。
谢谢
Firefox在URL栏中显示URL的解码版本,以便用户阅读。它仍然将编码后的字符串发送到服务器。
另外,如果您复制URL栏的内容并将其粘贴到文本编辑器中,它将在其中包含编码的字符。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句