如何重定向使用AJAX? [英] How to redirect using AJAX?
本文介绍了如何重定向使用AJAX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个code:
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?重定向= inbox.php(例如)
If the user is not logged in, it will add index.php?redirect=inbox.php (for example)
如何将用户登录到/inbox.php后?
How can i redirect the user after logging in to the /inbox.php ?
感谢你在前进!
推荐答案
Here's some code to get a URL parameter:
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_to_you_page使用()
功能:
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;
}
这篇关于如何重定向使用AJAX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文