0

当我运行 newuser() 函数时,它应该将一些信息发送回 index.php 文件。但是当我运行它时,什么也没有发生。我尝试了很多方法来找出问题所在,但没有运气。你们有人能在这段代码中发现问题吗?还是我应该编码的其他方式?

function newuser() {

            if (xmlHttp.readyState == 0 || xmlHttp.readyState == 4) {
                name = encodeURIComponent(document.getElementById("name").value);
                company = encodeURIComponent(document.getElementById("company").value);
                nationality = encodeURIComponent(document.getElementById("nationality").value);
                phonenumber = encodeURIComponent(document.getElementById("phonenumber").value);

                queryString = "name=" + name + "&company=" + company + "&nationalities=" + nationality + "&phonenumber=" + phonenumber + "&URL=newuser";
                xmlHttp.open("GET", "index.php?" + queryString, true);
                xmlHttp.onreadystatechange = handleServerRespons;
                xmlHttp.send();

           }else{
               setTimeout('newuser()', 1000)
           }  
    }

function handleServerRespons(){

    if (xmlHttp.readyState == 4){

        if (xmlHttp.readyState == 200){

            xmlResponse = xmlHttp.rsponseXML;
            xmlDocumentElement=xmlResponse.documentElement;
            message = xmlDocumentElement.firstChild.data;

            document.getElementById("underinput").innerHTML = message;

            }
        }
    }
4

1 回答 1

0

您的查询字符串错误(上面有太多问号字符)。将其更改为:

queryString = "name=" + name + "&company=" + company + "&nationalities=" + nationality + "&phonenumber=" + phonenumber + "&URL=newuser";
xmlHttp.open("GET", "index.php?" + queryString, true);
于 2013-06-25T16:32:23.343 回答