0

Hi guys i have a following code in which i am trying to redirect to another ,i am using javascript html to achieve this,and i am new to html, javascript and php. It is showing test.phpbut as i click on button it does not redirect to logout_success.php.

<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Sign-In</title> <link rel="stylesheet" type="text/css" href="style-sign.css"> 
    </head>
    <body id="body-color"> 
       <div id="Sign-In"> 
           <fieldset style="width:30%">
               <legend>LOG-IN HERE</legend> 
               <form method="POST" action="connectivity.php"> 
                   User
                   <br>
                   <input type="text" name="user" size="40">
                   <br> 
                   Password 
                   <br>
                   <input type="password" name="pass" size="40"><br> 

                   <input id="button" type="submit" name="submit" value="Log-In" onclick="document.location.href='http://localhost:8080/PortalWork/logout_success.php'"> 
               </form> 
           </fieldset> 
       </div> 
    </body> 
</html> 
James
  • 2,195
  • 1
  • 19
  • 22
CodeSniper
  • 493
  • 3
  • 12
  • 23

3 Answers3

1

There are two ways.

(1) Submit form with AJAX, and redirect with window.location.href

$("#form1").submit(function(e){
    e.preventDefault();
    $.ajax({
        url:'connectivity.php',
        method:'POST',
        success:function(rs){
            if( rs == "success" )
               window.location.href("logout_success.php");
        },
        error:function(){
            alert("Error");
        }
    });
    return false;
});

http://jsfiddle.net/hxm49uk2/

(2) Submit to server, and redirect with header("Location:page.php");

connectivity.php

header("Location:logout_success.php");
Parfait
  • 1,752
  • 1
  • 11
  • 12
0

You can do it in JS like this:

<button name="button" onclick="window.location.href='http://www.google.com'">Go</button>

Instead of http://www.google.com use your desired url.

  • Can you please suggest me one more thing that now i have `logout_success.php` on the same machine but what should i do if `logout_success.php` is on other machine having same LAN? – CodeSniper Sep 04 '14 at 11:33
  • I don't know that I understand you, but if you want that working on various PC in your LAN: http://stackoverflow.com/questions/10018955/how-to-access-my-localhost-from-another-pc-in-lan – Jacek Kaczmarek Sep 04 '14 at 12:11
0

Just include the following code in connectivity.php

header("Location:logout_success.php"); // give the correct path of logout_success.php

And take off onclick from form submit button

<input id="button" type="submit" name="submit" value="Log-In">
Adarsh Gowda K R
  • 941
  • 8
  • 15