如何用jQuery序列化来编码值? [英] How to encode value with jquery serialize?

查看:76
本文介绍了如何用jQuery序列化来编码值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试编码所有值,如$ / $>

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆