如何使用 ajax 和 get 请求将多个变量发送到 php 文件


How can I send more than one variable to a php file using ajax and a get request?

我正在尝试使用 ajax 将 I.D. 值和名称值发送到 php 文件。我可以只发送 I.D. 变量就可以了,但是当我尝试添加 name 变量时,函数停止工作。如何同时发送两者?

这有效:

function click() {
    var name = clickedelement.getElementsByTagName('input')[0].value;
    var id = clickedelement.getElementsByTagName('input')[1].value;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("popupBox").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "friends2.php?id="+id, true);
    xmlhttp.send();
};

但是当我尝试添加 name 变量时,它不起作用。

function click() {
    var name = clickedelement.getElementsByTagName('input')[0].value;
    var id = clickedelement.getElementsByTagName('input')[1].value;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("popupBox").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "friends2.php?id="+id"&name="+name, true);
    xmlhttp.send();
};

更改为"friends2.php?id="+id+"&name="+name 你只是缺少一个+

     "friends2.php?id="+id+"&name="
// missing plus sign here ^