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

$(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"){
return false;

You redirect using document.location not location.href


Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!