使用php和ajax进行未定义的索引

时间:2015-07-14 07:45:13

标签: javascript php ajax

为什么php中的var未定义? 代码html

<table>
    <tbody id="table">
        <tr>
            <th colspan="2">SignUp</th>
        </tr>
        <tr>
            <td>FirstName:</td><td>LastName:</td>
        </tr>
        <tr>
            <td><i class="fa fa-user"></i><input type='text' maxlength="25"autocomplete="off" size="20" id="fn"></td><td><i class="fa fa-user"></i><input type='text' maxlength="25"autocomplete="off"size="20" id="ln"></td>
        </tr>
        <tr>
            <td colspan="2"><div>DjName(Username):&nbsp; <i class="fa fa-headphones"></i><input type='text' maxlength="25"autocomplete="off"size="20" id="us"></div></td>
        </tr>
        <tr>
            <td>Password:</td><td>RePassword:</td>
        </tr>
        <tr>
            <td><i class="fa fa-unlock-alt"></i><input type='password' maxlength="25"autocomplete="off"size="20" id="pass"></td><td><i class="fa fa-unlock-alt"></i><input type='password' maxlength="25"autocomplete="off"size="20" id="repass"></td>
        </tr>
        <tr>
            <td>Email:</td><td>reEmail:</td>
        </tr>
        <tr>
            <td><i class="fa fa-envelope"></i><input type='text' maxlength="30"autocomplete="off"size="20"id="email"></td><td><i class="fa fa-envelope"></i><input type='text' maxlength="30"autocomplete="off"size="20" id="reEmai"></td>
        </tr>
        <tr>
            <td colspan="2"><button type="submit" id="Button">SignUp</button>
            </td>
        </tr>
        </tbody>
    </table>

代码javascript:

var httpAjax;
if(window.XMLHttpRequest)httpAjax= new XMLHttpRequest();
else httpAjax= new ActiveXObject('Microsoft.XMLHTTP');
httpAjax.onreadystatechange= function(){
  if(httpAjax.readyState== 4 && httpAjax.status== 200){
  }
};
httpAjax.open('POST','signup.php',true);
httpAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpAjax.send('firstname='+document.getElementById('fn').value+
'&lastname='+document.getElementById('ln').value+
'&djname='+document.getElementById('us').value+
'&password='+document.getElementById('pass').value+
'&repassword='+document.getElementById('repass').value+
'&email='+document.getElementById('email').value+
'&reEmail='+document.getElementById('reEmail').value);

代码php:

<?php
  $name=$_POST['firstname'];$lastname=$_POST['lastname'];$username=$_POST['djname'];$password= $_POST['password'];$repassword=$_POST['repassword'];$email= $_POST['email'];$remail= $_POST['remail'];
  echo $name,$lastname,$username,$password,$repassword,$email,$remail;
?>
这很奇怪。控制台没有给我错误,并已在这里待了很长时间。 我还想要解释一下error.thanks

  

注意:未定义的索引:第2行的C:\ xampp \ htdocs \ sito \ signup.php中的firstname
  注意:未定义的索引:第2行的C:\ xampp \ htdocs \ sito \ signup.php中的姓氏   注意:未定义的索引:第2行的C:\ xampp \ htdocs \ sito \ signup.php中的djname
  注意:未定义的索引:第2行的C:\ xampp \ htdocs \ sito \ signup.php中的密码
  注意:未定义的索引:第2行的C:\ xampp \ htdocs \ sito \ signup.php中的repassword
  注意:未定义的索引:第2行的C:\ xampp \ htdocs \ sito \ signup.php中的电子邮件
  注意:未定义的索引:第2行的C:\ xampp \ htdocs \ sito \ signup.php中的重新邮件

2 个答案:

答案 0 :(得分:1)

您要发送的内容类型包含拼写错误。它应该是 application / x-www-form-urlencoded ,而不是 application / x-www-orm-urlencoded

答案 1 :(得分:0)

您拥有最后一个元素的ID,因为reEmai不是reEmail,这可能导致发布数据的问题。

另外,您发布的代码中没有电子邮件或密码输入框。