2012-12-15 146 views
0

我是Ajax新手。在C類地址:在我的阿賈克斯,我得到了以下錯誤消息:未定義的索引:第4行的C: wamp www emailvalidate.php中的電子郵件

注意:未定義指數\ WAMP \ WWW \上 線4

測試\ sample.php我GOOGLE了,但我沒有對於我指定的問題沒有解決方案。

這是我做的。

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> 

我相信這是很簡單的問題,但我不知道該怎麼解決這個問題。任何幫助?

+0

什麼是你在地址欄輸入的網址? 「C:\ wamp \ www \ test \ sample.php」或「localhost/test/sample.php」 – Chella

+0

您是否在localhost或文件系統地址類型的url上檢查它? – Jai

回答

2

如果重命名input name="mail"...input name="address"一些光會有關情況散出您還沒有發送與address

一個名字,我承擔任何輸入。

作爲替代解決方案...變化:

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

這個

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

這不是問題。 $ _POST ['mail']是我項目中的變量,但我忘記更改我的示例代碼。現在我編輯了示例代碼,但情況相同。我認爲問題是別的 – klari

+0

如果你不打算髮布代碼的問題,但僞代碼,而不是我們將永遠無法幫助您 – Dale

+0

爲了我的好奇心,當我提交頁面時,值被傳遞給test2.php,但是當我使用Ajax時也沒有通過。可能是什麼問題 – klari

2

我沒有看到你的HTML代碼 '地址'。你有一個文本框:

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

但它的名字是「郵件」,而不是「地址」 你可以這樣做:

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

這不是問題所在。 $ _POST ['mail']是我項目中的變量,但我忘記更改我的示例代碼。現在我編輯了示例代碼,但情況相同。我認爲這個問題是別的 – klari

+0

爲了我的好奇心,當我提交頁面時,該值被傳遞給test2.php,但是當我使用Ajax時,這個值不會傳遞。可能是什麼問題 – klari

相關問題