我还可以在表单上使用其他东西来获取所有元素及其值,但不会将它们放入 URL 表示法中吗?或者有没有一种快速的方法来清理返回的字符串?
我得到了这个返回:
filePath=afile.doc&fileTitle=A+File&fileDescription=This+should+be+first+in+an+asc+sort%2C+last+in+a+desc
并且需要清理数据库提交的 URL 内容 - (“+”符号 nad %2C(逗号)。
是否有一种简单的方法可以反转标准 URL 编码表示法?
最佳答案
Is there something else I can use on a form to get all the elements and their values that won't put them into URL notation?
是的,您可以使用 jQuery 的 serializeArray
,这将“...将一组表单元素编码为名称和值的数组。”这将是最好的,因为您首先避免进行编码(我认为您想要使用值的未编码版本)。
示例:
var a, index, entry;
a = $("#theForm").serializeArray();
for (index = 0; index < a.length; ++index) {
entry = a[index];
display("a[" + index + "]: " + entry.name + "=" + entry.value);
}
Is there a simple way to reverse standard URL-encoded notation?
是的。各个编码值可以使用 decodeURIComponent
进行解码;完整的字段字符串可以使用 decodeURI
进行解码.
关于jquery序列化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5596573/