weixin_33743248 2015-05-23 12:03 采纳率: 0%
浏览 34

通过ajax发送两个变量

hey guys i have a problem when i'm trying to send two variables by ajax i did the same code w3schools used in this link http://www.w3schools.com/ajax/tryit.asp… but it only works when i use one variable only !! my code :

<script>
function showHintname() {
    var ln = document.getElementById("lname").value ;
    var fn= document.getElementById("fname").value ;
    if (fn.length == 0) { 
        document.getElementById("txtHint-name").innerHTML = "";
        return;
    }

    else {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint-name").innerHTML = xmlhttp.responseText;
            }
        }
        //xmlhttp.open("GET", "ini/name.php?f=" + fn , true); // working

        // xmlhttp.open("GET", "ini/name.php?f=" + fn &'l=' + ln , true); // not working
        xmlhttp.open("GET", "ini/name.php?f=1&l=1", true); // not working
        xmlhttp.send();
    }
}
</script>
  • 写回答

4条回答 默认 最新

  • 三生石@ 2015-05-23 12:13
    关注

    use this it will work

     xmlhttp.open("GET", "ini/name.php?f=" + fn+ "&l=" + ln , true);
    
    评论

报告相同问题?