[英]How to redirect to a new page?
当用户在特定页面中时,我应允许他们单击链接。 然后要显示的灯箱,一旦提交了灯箱内部的表单,就应该关闭灯箱并将用户重定向到索引页面。
我有两个JavaScript函数,第一个用于显示灯箱,第二个用于提交灯箱表单并使其褪色。 问题是我不知道如何将用户重定向到索引页面。
function rateItem(){
document.getElementById("box").style.display = "Block";
document.getElementById("frame").style.display = "Block";
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("box").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("get","../Item/rate",false);
xmlhttp.send();
return false;
}
function rate(id){
rate = $('#rate').val();
document.getElementById("box").style.display = "Block";
document.getElementById("frame").style.display = "Block";
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("box").style.display = "none";
document.getElementById("frame").style.display = "none";
window.location="http://localhost:9001/index"; << does not work
window.location.replace("http://localhost:9001/index"); <<does not work
}
}
xmlhttp.open("POST","../Item/submit?rate="+rate+"&id="+id,false);
xmlhttp.send();
}
任何jQuery解决方案也将不胜感激
更换线
window.location="http://localhost:9001/index";
有了这个
window.location.replace("http://localhost:9001/index");
对于基于jquery的重定向,请使用以下命令:
var url = "http://localhost:9001/index";
$(location).attr('href',url);
尝试使用:
window.location.href=url
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.