www.webdeveloper.com
Results 1 to 3 of 3

Thread: AJAX returns 500 on open("POST")

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Location
    USA and Sweden
    Posts
    2

    Question AJAX returns 500 on open("POST")

    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()

  2. #2
    Join Date
    Aug 2011
    Location
    USA and Sweden
    Posts
    2
    I forgot a ? in the login.php. Problem solved.

  3. #3
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    its always an extra curly bracket or aforgotten comma , soooo annoying

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles