在跳转之前先做一次登陆
var url="http://192.168.1.1:8000/doLogin"
$.ajax({
url:url,
data:{"userId":'admin','psw':'founder44'},
type:"post",
dataType:'json',
xhrFields:{withCredentials:true},
crossDomain:true,
success:function () {
//跳转方法
},
error:function () {
}
})
以为不同域名下服务器不会自动返回登录的cookie,设置withCredentials 表示从服务器强制获取证书,也就是说可以拿到cookie
跳转(跳转页面使用表单形式跳转)
function toNewPage(URL,PARAMS) {
console.log(PARAMS);
var temp_form = document.createElement("form");
temp_form .action = URL;
temp_form .target = "_blank";
temp_form .method = "post";
temp_form .style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp_form.appendChild(opt);
}
document.body.appendChild(temp_form);
temp_form .submit();
}