我的脚本出了什么问题?

时间:2010-06-04 23:09:55

标签: php ajax

我在Firebug中没有看到任何错误,我无法弄清楚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>

1 个答案:

答案 0 :(得分:2)

你不是POST任何东西。使用ajax表单时,会自动处理。

相关问题