gpt4 book ai didi

html - 表单输入值查询字符串顺序

转载 作者:行者123 更新时间:2023-12-01 17:42:48 27 4
gpt4 key购买 nike

具有相同名称的表单输入是可以的:

<form>
<input type="text" name="email">
<input type="text" name="email">
</form>

表单上的GET操作产生以下查询字符串:
...?email =&email =

因为电子邮件是自己存在的,所以可以。

现在,如果存在属于同一个人的数据(例如同一个人):
<form>
<input type="text" name="first_name">
<input type="text" name="last_name">

<input type="text" name="first_name">
<input type="text" name="last_name">
</form>

生成以下查询字符串:
...?first_name =&last_name =&first_name =&last_name =

我想查询字符串中的参数排序与html中出现的元素相同...不过,我不确定是否总是这样。

由于查询字符串本质上是键/值映射,因此排序无所谓...

我可以为每个名称添加一个索引,但是每次我要在客户端上添加新对时,都需要知道最后一个索引。

理想情况下,我希望避免自己添加索引以使结构更动态。

是否有一些更好的策略可以避免依赖查询字符串参数的顺序?名称上的数组表示法似乎是用于PHP的一种方法,但我希望有一种更通用的方法(不在服务器上使用PHP)...

最佳答案

I guess that the parameter ordering in the query string is the same as the elements appear within the html... nevertheless, I am not sure if this is always the case.



它是。

Because the query string is essentially a key/value map, ordering should not matter...



不是……虽然您可以将其视为一种。

Are there some better strategies to avoid relying on the order of the query string parameters?



取决于顺序是完全可以的。

Array notation on the name seems to be one way that is used for PHP but I would like to have a more generic way (not using PHP on the server)...



那是另一个可以接受的解决方案。有一些库可实现其他语言可用的PHP样式的查询解析。

您还可以使用JSON对数据进行编码…,但是随后您需要添加客户端JavaScript作为依赖项。

关于html - 表单输入值查询字符串顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57758878/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com