在尝试根据复选框内的值开发复选框激活的 mySQL 查询的过程中,我遇到了一个我无法解决的问题,我目前尝试了以下操作
<input type="checkbox" name="status" onclick="updateStatus(<? echo $data['id']; ?>,this.checked)">
函数“updateStatus”的 Javascript/Ajax 代码如下
function updateStatus(id,value) {
if (window.XMLHttpRequest) {
http = new XMLHttpRequest()
} else if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP")
} else {
alert("Your browser does not support XMLHTTP!")
}
http.abort();
http.open("GET", "../functions/ajax.php?check=update_status&id=" + id + "&checked="+value, true);
http.onreadystatechange = function () {
if (http.readyState == 4) {
alert(http.responseText);
}
}
http.send(null)
functions/ajax.php 中的 PHP 函数
if(isset($check) and $check == 'update_status' and isset($_GET['id'])){
$id = mysql_real_escape_string($_GET['id']);
$checked= mysql_real_escape_string($_GET['checked']);
if($checked == true) {
echo "Checked";
} elseif($checked == false) {
echo "Not checked";
} else {
echo "Invalid response";
}
使用此代码时,它总是返回“已检查”,知道为什么吗?