有了ajax调用,为什么可以';t我在php文档中使用这个$var post数据


With ajax call, why can't I use this $var post data inside my php document?

所以。。。是的,这是我调用ajax的函数。我想弄清楚为什么我的$value没有在showuser.php中定义??

function showUser2(value) {
                var xhr = new XMLHttpRequest();
                xhr.open("POST","showuser.php",true);
                xhr.onreadystatechange = function() {
                    if(xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById('container').innerHTML = xhr.responseText;
                    }
                }
                xhr.send("value="+value);
            }

showuser.php

<?php 
$value = $_POST['value'];
include_once("connect.php");
$obj = new User;
echo $value;
?>

这就是我如何调用javascript函数ajax。我试着把alert(value(放在函数showUser2((中,它正好给出了我想要的。。。

<select id="selConc" onChange='showUser2(this.value);'>
                <option>Choisissez par nom:</option>
                <?php $obj->unConc(); ?>
            </select>

尝试添加

xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");

在CCD_ 1之前。