On my website I have the following javascript/ajax code that is called when a user submits the logon form.
The login form then checks the information and passes back messages and PASS or ERROR.
On a success message I would then like the ajax to redirect to the php code again to double check for a valid logon before setting up the session, is this necessary? how would i "redirect" from within ajax whilst retaining the $_POST data?
//login form ajax
$("#login-form").submit(
function() {
$("#FormMessages").removeClass().addClass('alert alert-info').html(
'<img src="images/loading.gif" /> Validating....').fadeIn(500);
$.ajax({
url: $("#login-form").attr('action'),
dataType: 'json',
type: 'POST',
data: {
username : $('#email').val(),
password : $('#password').val()
},
success: function(data){
if (data.status == 'PASS') {
$("#FormMessages").fadeTo(
100,
0.1,
function()
{
$(this).html('Logging In...').removeClass().addClass(
'alert alert-success').fadeTo(450, 1,
function() {
document.location = curUrl;
});
});
} else {
$("#FormMessages").fadeTo(
200,
0.1,
function()
{
$(this).html('<h4>Error!</h4>')
.removeClass().addClass('alert alert-danger')
.fadeTo(450, 1);
$("#FormMessages").append('<ul>');
$(data.messages).each(function(i,obj) {
$("#FormMessages").append(''+obj+'');
});
$("#FormMessages").append('');
});
}
}
});
return false;
});
Thanks for reading!