将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屋!
查看全文