将对象序列化为JavaScript / jQuery中的查询字符串 [英] Serialize object to query string in JavaScript/jQuery

查看:247
本文介绍了将对象序列化为JavaScript / jQuery中的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找有关如何序列化对象以查询字符串格式的信息,但我的所有搜索都在结果中淹没了如何以其他方式(字符串/表单/以及JSON)。

I'm trying to find information on how to serialize an object to query string format, but all my searches are drowning in results on how to go the other way (string/form/whatever to JSON).

我有

{ one: 'first', two: 'second' }

我想要

?one=first&two=second

有没有好方法可做这个?我不介意插件或其他东西 - 如果我找到的代码不是插件,我可能会把它重新写成一个...

Is there a good way to do this? I don't mind plugins or whatnots - if the code I find is not a plugin, I'll probably re-write it to one anyway...

推荐答案

你想 $ .param() http://api.jquery.com/jQuery.param/

具体来说,你想要这个:

Specifically, you want this:

var data = { one: 'first', two: 'second' };
var result = $.param(data);

如果给出以下内容:

{a: 1, b : 23, c : "te!@#st"}

$ .param 将返回此信息:

a=1&b=23&c=te!%40%23st

这篇关于将对象序列化为JavaScript / jQuery中的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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