![](/img/trans.png)
[英]Why can't I end my if statement with document.getElementById(“ID”).value = var?
[英]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。 我试图将警报(值)放在我的函数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");
在xhr.send(...)
之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.