ajax redirect issue
i want to redirect form after ( success ) to another page. i use this code
开发者_如何学C$(document).ready(function(){ $("#ajax-form").submit(function(){ $.post( "ajaxContact/ajax-register.php", $("#ajax-form").serialize(), function(data){ if (data.success) $("span#ajax-message").css({'color':'green'}); window.location("index.html"); else $("span#ajax-message").css({'color':'red'}); $("span#ajax-message").html(data.message); }, "json" ); return false; });
});
how to redirect.
Regards
If you want to just redirect the page there, this should work:
if(data.success)
window.location = "url";
Updated:
$(document).ready(function()
{
$("#ajax-form").submit(function()
{
$.post("ajaxContact/ajax-register.php", $("#ajax-form").serialize(),
function(data)
{
if (data.success)
{
//If successful...
window.location = 'http://www.google.com';
}
else
{
//If unsuccessful...
alert("Post was unsuccessful.");
}
},"json");
return false;
});
});
That should work for you as long as your post is returning successfully. Here's a demo using a confirm to imitate your Post:
Demo here
window.location = "http://www.google.com";
精彩评论