Maybe I'm doing this wrong, but here's what I'm trying to do.
Ok, so how do I send the URL to a new page? Right now I understand the writing ajax to a div, replacing the contents of the div, appending it etc. But what about if I am using the below code, for like a login area, I can get the form to return wrong username etc based on the submitting, but if everything checks out as correct in my ajax-login.php file, the form doesn't follow the headers at the bottom of the page. What would I use to make it follow the headers from this page? Or is there a better way?
Thanks
ajax-login.php
a bunch of code, grabbing the values from the form and checking if they are valid passwords and things like that like;
if ($usernamecheck == ''){
echo "<div id=\"log_res2\">";
echo "<span class=\"error\">*Must enter a username.</span><br />";
echo "</div>";
}else{
header("location: /index.php");
}
And my ajax is
$(document).ready(function()
{
$("#Login").click(function(){
var $password = $("#password").val();
var $username = $("#username").val();
var dataString = 'username=' + $username + '&password=' + $password;
$.ajax({
type: "POST",
url: "../includeajax/ajax-login.php",
data: dataString,
cache: false,
success: function(html){
$("#log_res2").replaceWith(html);
}
});
return false;
});
});
I get the errors when I put in the wrong usernames or passwords, but how do I return that header to make it redirect to a new page when there aren't any errors?
Thanks