widow.location.href传参问题

weixin_46447603 2020-03-22 06:28:08
想通过Ajax到servlet验证登录,返回0验证成功,并且带着参数aid跳转到下一个jsp,该怎么修改呢

登录的jsp和Ajax

<form name="login" class="form-group">
<div class="form-group">
<label><div class="ge">管理员:</div>
<input name="aid" class="form-control" type="text" placeholder="请输入工号">
</label>
</div>
<div class="form-group">
<label><div class="ge">密码:</div>
<input name="apwd" class="form-control" type="password" placeholder="请输入密码">
</label>
</div>

<button class="btn btn-primary" type="button" onclick="ajaxsub(aid,apwd)">登录</button>
</form>

<script>
function createXMLHttpRequest(){.....省略}
function ajaxsub(t,z) {
createXMLHttpRequest();
if (xmlhttp != null) {
var url = "http://localhost:8080/SAnimals/aloginServlet";
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlhttp.onreadystatechange = callfun;
xmlhttp.send("aid="+t.value+"&apwd="+z.value);
}
else {
alert("不能创建XMLHttpRequest对象实例");
}
} //回调函数

function callfun() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var serviceData = xmlhttp.responseText;

if (serviceData == "1") {
alert("密码错误!");
} else if (serviceData == "-1"){
alert("请填写工号和密码!");
} else if(serviceData == "0"){//登录验证成功

window.location.href("me.jsp");怎么带上参数aid呢
}

}
}
}
</script>



拜托各位了,非常感谢!
...全文
145 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_46447603 2020-03-22
  • 打赏
  • 举报
回复
引用 5 楼 qybao 的回复:
have a try window.location.href=“https://xxx/me.jsp?aid=“+aid.value;
这样写之前就试过,也不行,不过还是谢谢啦!!我已经解决了!非常感谢!
weixin_46447603 2020-03-22
  • 打赏
  • 举报
回复
我解决了!用的这个: var d = document.getElementById('aid').value; location.href = 'me.jsp?aid=' + d;
qybao 2020-03-22
  • 打赏
  • 举报
回复
have a try window.location.href=“https://xxx/me.jsp?aid=“+aid.value;
weixin_46447603 2020-03-22
  • 打赏
  • 举报
回复
引用 2 楼 独行客Boss 的回复:
window.location.href= 你的url
可我的意思是还要带上参数呀,这样,不带参数可以成功跳转,但是带参数的我不会改
weixin_46447603 2020-03-22
  • 打赏
  • 举报
回复
引用 1 楼 qybao 的回复:
href(“me.jsp?aid=“+aid.value); 试试
这样不行,Ajax传到了servlet并且给了正确的返回值0,但是不跳转
独行客Boss 2020-03-22
  • 打赏
  • 举报
回复
window.location.href= 你的url
qybao 2020-03-22
  • 打赏
  • 举报
回复
href(“me.jsp?aid=“+aid.value); 试试

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧