寻找类似php函数http_build_query的JavaScript实现 - 在GET / POST方法中将嵌套的JavaScript对象作为请求参数发送。
示例对象:
var params = {
codes: [
{
id: 1212,
name: "log",
},
{
id: 123,
name: "console",
}
],
ajaxsettings : { "ak1" : "v1", "ak2" : "v2"},
uisettings : { "ui1" : "v1", "ui22" : "v2"},
};
请帮忙。
答案 0 :(得分:0)
如果允许使用jQuery,您可以使用$.param()
var query = $.param(params);
var params = {
codes: [
{
id: 1212,
name: "log",
},
{
id: 123,
name: "console",
}
],
ajaxsettings : { "ak1" : "v1", "ak2" : "v2"},
uisettings : { "ui1" : "v1", "ui22" : "v2"},
};
var query = $.param(params);
console.log(query);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>