// 获取url参数
function getUrlVars() {
var vars = {};
var parts = decodeURI(window.location.href).replace(/[?&]+([^=&]+)=([^&#]*)/gi,
function(m,key,value) {
vars[key] = value;
}
);
return vars;
}
var data = getUrlVars()
// 浏览器不刷新时执行
if (performance.navigation.type != 1) {
// ajax请求
function scanFun() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://127.0.0.1:8000/user/?uid="+data.uid+"&name="+data.name, true);
// xhr.setRequestHeader("content-type","application/x-www-form-urlencoded");//设置请求头
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var res = xhr.responseText;
console.log('res', res);
}
}
};
scanFun();
}
JS获取URL参数和ajax请求
最新推荐文章于 2021-12-30 10:38:56 发布