Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何重定向到新页面?_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 如何重定向到新页面?

Javascript 如何重定向到新页面?,javascript,jquery,ajax,Javascript,Jquery,Ajax,当用户处于特定页面时,我应该允许他们单击链接。然后显示一个lightbox,一旦lightbox中的表单被提交,lightbox应该被关闭,用户应该被重定向到索引页面 我有两个javascript函数,第一个用于显示lightbox,第二个用于提交lightbox表单并使其褪色。问题是我不知道如何将用户重定向到索引页面 function rateItem(){ document.getElementById("box").style.display = "Block"; docu

当用户处于特定页面时,我应该允许他们单击链接。然后显示一个lightbox,一旦lightbox中的表单被提交,lightbox应该被关闭,用户应该被重定向到索引页面

我有两个javascript函数,第一个用于显示lightbox,第二个用于提交lightbox表单并使其褪色。问题是我不知道如何将用户重定向到索引页面

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();
}
function rateItem(){
document.getElementById(“box”).style.display=“Block”;
document.getElementById(“frame”).style.display=“Block”;
if(window.XMLHttpRequest)
{
xmlhttp=新的XMLHttpRequest();
}
其他的
{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“box”).innerHTML=xmlhttp.responseText;
} 
}
open(“get”、“./项目/费率”,false);
xmlhttp.send();
返回false;
}
功能速率(id){
比率=$(“#比率”).val();
document.getElementById(“box”).style.display=“Block”;
document.getElementById(“frame”).style.display=“Block”;
if(window.XMLHttpRequest)
{
xmlhttp=新的XMLHttpRequest();
}
其他的
{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“box”).style.display=“无”;
document.getElementById(“frame”).style.display=“无”;
window.location=”http://localhost:9001/index“;尝试使用:

  window.location.href=url
尝试使用:

  window.location.href=url
尝试使用:

  window.location.href=url
尝试使用:

  window.location.href=url
更换线路

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="http://localhost:9001/index"; 
用这个

window.location.replace("http://localhost:9001/index");
对于基于jquery的重定向,请使用以下命令:

var url = "http://localhost:9001/index";    
$(location).attr('href',url);
更换线路

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="http://localhost:9001/index"; 
用这个

window.location.replace("http://localhost:9001/index");
对于基于jquery的重定向,请使用以下命令:

var url = "http://localhost:9001/index";    
$(location).attr('href',url);


可能重复的@Rob我已经试过了,可能重复的@Rob我已经试过了,可能重复的@Rob我已经试过了,可能重复的@Rob我已经试过了,可能重复的@Rob我已经试过了,可能重复的@Rob我已经试过了,可能重复的@Rob我也没有试过你的代码;如果我对框和框架元素进行注释并放置其他一些有效的url。两个都有效,你想在浏览器中点击url吗?还要在控制台中检查javascript错误。两个地址都正确,firebug显示它试图重定向到localhost:9001/index几乎一秒钟,然后重定向到当前页。@J888那么可能索引页被转发到此页。你一定已经得到了now、 请分享您的代码;如果我对框和框架元素进行注释,并放置一些其他有效的url,对我来说效果很好。这两种方法都有效,您尝试在浏览器中点击url吗?还要在控制台中检查javascript错误。这两个地址都是正确的,firebug显示它尝试重定向到localhost:9001/index几乎一秒钟,然后重定向到current页。@J888那么索引页可能是转发到此页的。您一定已经得到了现在缺少的内容,请共享您的代码;如果我对框和框架元素进行注释并放置一些其他有效的url,对我来说效果很好。这两种方法都有效,您尝试在浏览器中命中url吗?同时在控制台中检查javascript错误。两个地址都是正确的,firebug显示它试图重定向到localhost:9001/index几乎一秒钟,然后重定向到当前页面。@J888然后可能索引页面被转发到此页面。您一定已经得到了现在缺少的内容,请共享您的代码;如果我对框和框架元素进行注释并放置一些其他有效url,对我来说效果很好。这两种方法都有效,您正在尝试吗在浏览器中点击url?同时在控制台中检查javascript错误。两个地址都正确,firebug显示它试图重定向到localhost:9001/index几乎一秒钟,然后重定向到当前页面。@J888然后可能索引页面被转发到此页面。您现在一定已经得到了缺少的内容,请共享它