簡體   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