July 24, 2013
Jquery redirect after php login
Kingofslowmo’s Question:
The Problem
I can’t seem to get the javascript to redirect after the php has echoed “Success”.
Im basically just trying to make it where the javascript post my form data and then the usesr is redirected to their account page. I did have this being done via php, but I wanted the luxury of being able to stay on the same page while logging in.
The Javascript
<script>
$(document).ready(function() {
//When the form with id="myform" is submitted...
$("#login_form").submit(function() {
//Send the serialized data to formProcessor.php.
$.post("login.php", $("#login_form").serialize(),
//Take our repsonse, and replace whatever is in the "formResponse"
//div with it.
function(data) {
if(data == "Success"){
location.href="home";
}
}
);
return false;
});
});
</script>