将 javascript 对象转换为 URL 参数 [英] Convert javascript object to URL parameters
本文介绍了将 javascript 对象转换为 URL 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我意识到从根本上我可能会以错误的方式解决这个问题,所以我愿意接受任何朝着正确方向前进的努力.
I realize that fundamentally I'm probably going about this the wrong way so I'm open to any pushes in the right direction.
我正在尝试使用 HipChat API 向房间发送通知,如下所示:
I'm trying to use the HipChat API to send a notification to a room like so:
https://www.hipchat.com/docs/api/method/rooms/message一个>
我正在尝试使用 js 对象的参数构建示例中的 URL,所以基本上我正在尝试转换:
I'm trying to build the URL in the example with a js object's parameters, so basically I'm trying to convert this:
var hipChatSettings = {
format:"json",
auth_token:token,
room_id: 1,
from: "Notifications",
message: "Message"
}
为此:
推荐答案
你应该检查这个 jQuery.param函数.
var params = { width:1680, height:1050 };
var str = jQuery.param( params );
console.log(str);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
这篇关于将 javascript 对象转换为 URL 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文