为什么来自服务器的echo(PHP)会向响应中添加额外的xml信息?

为什么来自服务器的echo(PHP)会向响应中添加额外的xml信息?,php,javascript,Php,Javascript,我用debug单独检查了服务器端,它正常工作 它正在创建一个由0和1组成的字符串,并将其发送回客户端 在服务器端,它看起来是这样的: if (validateInput($_POST["user"], $_POST["password1"], $_POST["password2"], $_POST["email1"], $_POST["email

我用debug单独检查了服务器端,它正常工作 它正在创建一个由0和1组成的字符串,并将其发送回客户端

在服务器端,它看起来是这样的:

    if (validateInput($_POST["user"],
                  $_POST["password1"],
                  $_POST["password2"],
                  $_POST["email1"],
                  $_POST["email2"]))
{
    $_subscriber =  new subscriber($_POST["user"],$_POST["password1"],$_POST["email1"],CURRENT_TIME);
    subscriberInsertion($_subscriber);
}
/** function subscriberInsertion($_subscriber) insert a subscriber to DB*/
function subscriberInsertion($_subscriber)
{

    $query = "INSERT INTO users (user,value,email,date) VALUES('{$_subscriber->getUser()}',
                                                              '{$_subscriber->getPassword()}',
                                                              '{$_subscriber->getEmail()}',
                                                              '{$_subscriber->getDate()}')";

    $dbObj = new DB_MySQL(DB_users_HOST,DB_users_USER,DB_users_PASS,DB_users_NAME);
    if ($dbObj ->execute($query))
    {
        header('Location:' . URL_HTML_PATH . "index.html");
        exit;
    }
}


/**validateInput main function for validation of good credntails and emails */
function validateInput($user,$pass1,$pass2,$email1,$email2)
{
    $regexUser = "/^(?=.{1,20}$)[a-zA-Z0-9]+$/";      //all letters ad number and size between 1-20
    $regexPwd = "/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,10}$/"; //Password must contain 6-10 characters and
                                                             // at least one number, one letter and one
    //Regex mail
    $regexMail = "/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/";

    $response = "";

    //check user name//

    $response = $response . checkRegex($regexUser,$user); //at location 0 in string

    //check password//

    $response = $response . checkRegex($regexPwd,$pass1); //at location 1 in string
    $response = $response . textCompare($pass1,$pass2); //at location 2 in string

    //check mail//

    $response = $response . checkRegex($regexMail,$email1); //at location 3 in string
    $response = $response . textCompare($email1,$email2); //at location 4 in string

    //check user name existence


    $response = $response . checkExistaneceOfUser($user); //at location 5 in string

    echo $response;

}
我从服务器端得到的响应很好问题是我接收到一个奇怪的xml:


(!)注意:未定义索引:第25行D:\wamp\www\MyHome2\php\databasebuilder.php中的email2
调用堆栈
#时间记忆功能定位
10.0010163616{main}()..\databasebuilder.php:0
001011“


我在这里只放了xml的一小部分,因为它太大了,正如您在xml末尾看到的那样,我得到了001011,这是我期望的响应。为什么我得到这个xml和我的结果?我如何去掉它?

您看到的是
xDebug
的输出

当您出现php错误时,将显示此信息

错误来自代码示例的第5行

代码:
$\u POST[“email2”]

错误:
注意:未定义索引:email2

提交表单时,您没有通过POST发送电子邮件2的值


在调用validate函数之前,您可以使用
isset
()解决此问题,该函数在第25行的D:\wamp\www\MyHome2\php\databasebuilder.php中显示“注意:未定义的索引:email2”“。我认为这与您的代码有关,特别是databasebuilder.php的第25行。谢谢,实际上问题出在password2字段上,我无意中将它与标记password22一起发送,但这回答了一个问题
/**function checkUserExistance(str) to check if user exist*/
function sendToValidation(data)
{
    var xmlhttp;

    xmlhttp=new XMLHttpRequest();



    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var response = xmlhttp.responseText;
            alert(response);


         }
    }


     xmlhttp.open("POST",url + page,true);
     xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlhttp.send(data);
}