字符串编码 html
我使用 javascript 和 Node.js 实现了一个 http 服务器。
由于某种原因,当用户填写表格时,让我们说出他的全名, 在服务器端,我得到用户填写的内容,但是..我在所有单词之间得到“+”而不是“”。
这是客户端:
<form id="register" action="/register" method="post">
<input type="text" id="reg_usname" class="input" name="username" required autofocus/>
<form />
这是服务器端:
var username=request.parameters['username'];//request is an http request that is returned
我不知道为什么会这样。
我可以简单地将所有“+”替换为“”,但似乎有一种更聪明的方法来解决这个问题。
I implemented an http server using javascript and Node.js.
for some reason when the user fills in a form, let's say his full name,
on the server side i get what the user filled in but.. i get "+" between all the words instead of " ".
this is the client side:
<form id="register" action="/register" method="post">
<input type="text" id="reg_usname" class="input" name="username" required autofocus/>
<form />
this is the server side:
var username=request.parameters['username'];//request is an http request that is returned
I have no idea why it is that way.
I can just simply replace all the "+" to " " but it seems that there is a smarter way to fix the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您传回服务器的数据正在被 URL 编码。
这是来自编写者的 RFC 规范,它解释了如何&为什么。
您可以在此 Mozilla 开发者网络页面上找到可用于编码/解码的 JavaScript 函数。
The data you are passing back to the server is being URL Encoded.
Here's a the RFC spec from the people who wrote it that explains how & why.
The JavaScript functions you can use to encode/decode can be found on this Mozilla Developer Network page.