Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
Jquery 如何使用AJAX重定向?_Jquery_Ajax - Fatal编程技术网

Jquery 如何使用AJAX重定向?

Jquery 如何使用AJAX重定向?,jquery,ajax,Jquery,Ajax,我有以下代码: function get_login() { hideshow('loading2',1); error(0); $.ajax({ type: "POST", url: "The URL", data: $('#logins').serialize(), dataType: "json", success: function(msg){ if(p

我有以下代码:

function get_login()
{
    hideshow('loading2',1);
    error(0);

    $.ajax({
        type: "POST",
        url: "The URL",
        data: $('#logins').serialize(),
        dataType: "json",
        success: function(msg){  

            if(parseInt(msg.status)==1)
            {
                succ2(1,msg.txt);                   
                setTimeout('go_to_you_page()', 1000);

            } else if(parseInt(msg.status)==0) {
                error2(1,msg.txt);
            }

            hideshow('loading2',0);
        }
    });

    return false;
}

function go_to_you_page()  
{  
    window.location = 'myaccount.php';     
} 
如果用户未登录,它将添加
index.php?redirect=inbox.php
(例如)

登录到
/inbox.php
后如何重定向用户

提前谢谢你

下面是获取URL参数的步骤:

function get_url_parameter(name) {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if ( results == null )
      return "";
    else
      return results[1];
}
您可以在
go\u to\u You\u页面()中使用此选项。
函数:

function go_to_you_page()
{
    var redirect_parameter = get_url_parameter('redirect');

    // redirect to /myaccount.php if the redirect parameter is not set
    var redirect = ( redirect_parameter === "" ) ? 'myaccount.php' : redirect_parameter;

    window.location.href = redirect;
}

问题到底是什么?您似乎拥有基于链接实现重定向的正确代码。请在成功处理程序中设置window.location,或在XHR回复中使用响应重定向进行回复。回答正确,但根据帖子window.location.replace比window.location.href更好。请查看