JS函数将一个空字符串传回php,但有一个值

JS function passing an empty string back to php, but has a value?

本文关键字:php 有一个 字符串 函数 一个 JS      更新时间:2023-09-26

所以我试图将几个值传递回这样的PHP页面。

function showAccountInfo(obj){
    var value = obj.value;
    var content = obj.querySelector("option:checked").textContent;
    alert("value: " + value + " content: " + content);
    if(obj == ""){
        return;
    }
    else {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("facilities").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","getinfo.php?=q"+value+"&c="+content, true);
        xmlhttp.send(); 
    }
}

当警报响起时,它会向我显示每个变量的正确值。但是,当我将该值传递给getinfo.php并使用变量value来完成查询并将其回显到页面时,它显示为空。

$q = ($_GET['q']);
$sql = "SELECT *, account.account_name FROM facility "
 . "INNER JOIN account ON account.account_id = facility.account_id "
 . "WHERE facility.account_id = '".$q."'";
echo $sql;

结果:SELECT *, account.account_name FROM facility INNER JOIN account ON account.account_id = facility.account_id WHERE facility.account_id = ''

在我之前的问题之前,我的一切都正常。

您的url格式不正确

更改

xmlhttp.open("GET","getinfo.php?=q"+value+"&c="+content, true);
                                ^

xmlhttp.open("GET","getinfo.php?q="+value+"&c="+content, true);
                                 ^

注意第一个= 的变化

相关文章: