Hello, I'm a pretty experienced web developer but when I recently looked into using AJAX to send POST information to the server I'm just getting the 500 error response from the server.
I'm also using jQuery to hide and show content but I'm having no issues with that.
index.php source code:
PHP Code:
<!DOCTYPE>
<?php
$topLinks 
= array("home","about","contact");
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <title> Main Page </title>
    </head>
    <body>
        <!-- Icons by Mark James - http://www.famfamfam.com/lab/icons/silk/ -->
        <!-- Thanks to 13 Styles http://13styles.com/css-menus/matte/ -->
        <ul id="header">
            <?php
                
foreach ($topLinks as $oput) {
                    if ( 
$_GET["link"] == $oput ) {
                        echo 
"<li class='active'><a href='?link=" $oput "'>" $oput "</a></li>";
                    }
                    else
                    {
                        if ( 
$_GET["link"] == "" && $oput == "home" ) {
                            echo 
"<li class='active'><a href='?link=" $oput "'>" $oput "</a></li>";
                        }
                        else
                        {
                            echo 
"<li><a href='?link=" $oput "'>" $oput "</a></li>";
                        }
                    }
                }
            
?>
        </ul>
        <div class="content">
            <div id="menu">
                <div id="signin">
                    <?php include("include/user_management.php"); ?> <br>
                </div>
            </div>
            <div id="text">
                <h1>The Main Text</h1>
                <p>Welcome to the webpage!</p>
                <p>Use the left menu to login</p>
            </div>
        </div>
        <div class="footer">
            Webdesign by <a href="http://www.google.com/recaptcha/mailhide/[snip]">[snip]</a>
        </div>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
        <script src="js/sidebar.js"></script>
        <script src="js/ajax.js"></script>
    </body>
</html>
JavaScript Source Code:
Code:
function loginLaunch() {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            $("#signin").hide(500, function () {
                document.getElementById("#signin").innerHTML = xmlhttp.responseText;
                $("#signin").show(500);
            });
        }
    };
    xmlhttp.open("POST", "http://localhost/include/login.php", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send("username="
    + document.forms["login"]["username"].value
    + "&password="
    + document.forms["login"]["password"].value);
}
include/user_management.php source code:
PHP Code:
<?php
    
if ( $_COOKIE["user"] != "" || $_COOKIE["user"] != null ) {
        echo 
"There's a cookie for me!! Omnomnomnom!!<br>";
        echo 
$_COOKIE["user"];
        echo 
$_COOKIE["user_key"];
    }
    else {
        
?>
        <h3>Login:</h3>
        <!-- Start Form -->
        <form name="login" class="login" action="include/login.php" method="post">
        Username: <input type="text" name="username" />
        Password: <input type="password" name="password" />
        <button type="button" onclick="loginLaunch();">Login</button><br>
        </form>
        <?php
    
}
?>
login.php debug sourcecode:
PHP Code:
<?php
    
echo "Some response!";
    
//echo $_POST["username"];
    //setcookie("user", $_POST["username"], time() + 10);
    //setcookie("user_key", crypt($_POST["username"] . time()), time() + 10);
>
I'm assuming that the problem is in the JavaScript where I'm using the xmlhttp.send()