tags:

views:

38

answers:

1

I don't see any errors in Firebug, and I can't figure out what's wrong with the AJAX.

PHP:

<?php


$subject = $_POST['subject'];

echo $subject;



?>

Javascript

  <html>
<head>
<script type="text/javascript">
/* <![CDATA[ */ 

    function ajax() {


        if (window.XMLHttpRequest) {
            xmlhttp=new XMLHttpRequest();           
        } else {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("result_div").value = xmlhttp.responseText;
            }
        }
        xmlhttp.open("POST","message.php",true);
        xmlhttp.send();

        return false;
    }

    /* ]]> */ 
</script>
</head>
<body>
<div id="result_div"></div>
<form action="" onsubmit="return ajax();">

    <select name="teest">
        <option value="hi">hi</option>
    </select><br />

    <input type="text" name="subject"> <br />
            <input type="submit">

</form>

</body>
</html>
+2  A: 

You are not POSTing anything. When using ajax forms are not handled automatically for you.

Jakub Hampl
Is it more ideal to use get or post?
Doug
Nothing is posted because xmlhttp.send(); is empty. xmlhttp.send('subject=hello'); should set the div value to hello.
Tony Lee
Get vs post see: http://stackoverflow.com/questions/715335/get-vs-post-in-ajax
Tony Lee