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

查看:20
本文介绍了序列化对象以在 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天全站免登陆