如何用jQuery序列化来编码值? [英] How to encode value with jquery serialize?
问题描述
我尝试编码所有值,如$ / $>
encodeURIComponent($(#customer_details)。serialize());
并且不能按预期工作。
是否有办法获取表单上的所有元素并使用 encodeURIComponent
来编码每个值?
使用 serialize()
[docs] 方法。
从文档:
$ b
.serialize()
方法以标准URL编码创建一个文本字符串
示例: http://jsfiddle.net/WArUG/
如果您想用%20
而不是 +
,你需要做一个 .replace(/ \ + / g,'%20')
。
I tried to encode all values like
encodeURIComponent($("#customer_details").serialize());
and that doesn't work as expected.
Is there way to get all elements on form and use encodeURIComponent
to encode each value?
It should already be encoded when using the serialize()
[docs] method.
From the docs:
The
.serialize()
method creates a text string in standard URL-encoded notation.
Example: http://jsfiddle.net/WArUG/
If you want to represent a space with a %20
instead of a +
, you'll need to do a .replace(/\+/g,'%20')
.
这篇关于如何用jQuery序列化来编码值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!