字符串编码 html

发布于 2025-01-02 04:08:36 字数 539 浏览 4 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝海 2025-01-09 04:08:36

您传回服务器的数据正在被 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文