Flask接口签名sign原理与实例代码浅析
202
2023-08-07
javascritp添加url参数将参数加入到url中
将对象参数加入到url中,如果原来url中有则覆盖
js代码
function addToUrl(obj){
var aprotocol = location.protocol;
var ahost = location.host;
var apath = location.pathttp://hname;
var asearch = location.search;
var ahash = location.hash;
var result = '';
console.log(obj);
var joinObj = function(joinObj_obj){
var result = '';
for(var i in joinObj_obj){
result += i + '=' + joinObj_obj[i];
}
return result;
};
var splitSearchToObj = function(str){
var resObj = {};
var arr = str.split('&');
for(var i = 0; i < arr.length; i++){
resObj[arr[0]] = arr[1];
}
return resObj;
};
var existObjKey = function(existObjKey_obj, str){
for(var i in existObjKey_obj){
if(i == str){
return true;
}
}
return false;
};
var objExtend = function(obj1, obj2){
var result = {};
for(var i in obj1){
if(existObjKey(obj2, i)){
result[i] = obj2[i];
}else{
result[i] = obj1[i];
}
}
};
if(asearch == ''){
console.log(obj);
result = aprotocol + '//' + ahost + apath + '?' + joinObj(obj) + ahash;
}else{
var oldSearchObj = splitSearchToObj(asearch.substr(1));
result = aprotocol + '//' + ahost + apath + joinObj(objExtend(oldSearchObj, obj)) + ahash;
}
return result;
}
addToUrl({'kd': 'aaa'});
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~