繁体   English   中英

未定义索引:第 4 行 C:\wamp\www\emailvalidate.php 中的电子邮件

[英]Undefined index: email in C:\wamp\www\emailvalidate.php on line 4

我是阿贾克斯的新手。 在我的 Ajax 中,我收到以下错误消息:

注意:未定义索引:第 4 行 C:\wamp\www\test\sample.php 中的地址

我用谷歌搜索,但我没有为我指定的问题找到解决方案。

这就是我所做的。

带有 Ajax 的 HTML 表单 (test1.php)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("mydiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST","test2.php",true);
xmlhttp.send();
}
</script>


</head>

<body>
<form id="form1" name="form1" method="post" action="test2.php">
  <p>
    <label for="address"></label>
    <input type="text" name="address" id="address" onblur="loadXMLDoc()"  />
    <input type="submit" name="submit" id="submit" value="Submit" />
  </p>
  <p><div id = 'mydiv'></div></p>
</form>
</body>
</html>

test2.php

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
echo "Your Address is ".$_POST['address'];
?>

</body>
</html>

我确信这是一个非常简单的问题,但我不知道如何解决它。 有什么帮助吗?

您没有发送任何带有address名称的输入

我假设如果您将input name="mail"...重命名为input name="address" ,将会对这种情况有所了解。

作为替代解决方案...更改:

<?php
echo "Your Address is ".$_POST['address'];
?>

对此

<?php
echo "Your Address is ".$_POST['mail'];
?>

我没有在您的 HTML 代码中看到“地址”。 你有一个文本框:

<input type="text" name="mail" id="mail" onblur="loadXMLDoc()"  />

但它的名称是“邮件”,而不是“地址”你可以这样做:

<?php
echo "Your Address is ".$_POST['mail'];//instead of 'address'
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM