$.param()的实例应用

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>

<pre>
var jumpUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?'
var params = {
appid: 'ssssss', // 公众号appid
redirect_uri: 'http://woejfoa.com/a/s.html', //回调地址,域名配置同一地址 定位到目录
response_type: 'code',
scope: 'snsapi_userinfo',// 需要用户确认登录
state: 'STATE'
}
jumpUrl += $.param(params) + '#wechat_redirect';
console.log(jumpUrl);
jQuery.param()函数用于将一个JS数组或纯粹的对象序列化为字符串值,以便用于URL查询字符串或AJAX请求。

</pre>


<script src="js/jquery.min.js"></script>
<script>

var jumpUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?'
var params = {
appid: 'ssssss', // 公众号appid
redirect_uri: 'http://woejfoa.com/a/s.html', //回调地址,域名配置同一地址 定位到目录
response_type: 'code',
scope: 'snsapi_userinfo',// 需要用户确认登录
state: 'STATE'
}
jumpUrl += $.param(params) + '#wechat_redirect';
// location.href = jumpUrl // 获取code跳转到回调地址
console.log(jumpUrl);
// jQuery.param()函数用于将一个JS数组或纯粹的对象序列化为字符串值,以便用于URL查询字符串或AJAX请求。
/* https://open.weixin.qq.com/connect/oauth2/authorize?appid=ssssss&redirect_u….html&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect*/
</script>
</body>
</html>

原文地址:https://www.cnblogs.com/studyh5/p/7753684.html