在config.js中,對參數進行解析
config.tools = {
/**
* 獲得get請求參數
* 例如:
* ?q=javascript&num=10
* var args = getQueryStringArgs();
* alert(args["q"]);//"javascript"
* alert(args["num"]);//"10"
* @return {}
*/
getQueryStringArgs: function () {
var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
args = {},
items = qs.length ? qs.split("&") : [],
item = null, name = null,
value = null, i = 0,
len = items.length;
for (i = 0; i < len; i++) {
item = items[i].split("=");
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
if (name.length) {
args[name] = value;
}
}
return args;
},
在js中訪問後臺接口
function searchFollow(){
var row = $('#grid').datagrid("getSelected");
console.log(row)
if(row) {
location.href = serverBasePath + "/admin/follow/follow?id=" + row.id + "&nickName="+ row.nickName;
}else{
config.alert("請選擇一條記錄")
}
}
在接收頁面獲取傳過來的值
var params = config.tools.getQueryStringArgs();
var id = params.id;