AJAX xmlHttp请求获取未定义的索引XML读取文件


AJAX xmlHttp request GET undefined Index XML read file

当我试图将从客户端(javascript/AAJAX)的下拉框中选择的值发送到服务器端(php)时,我在服务器端收到一条未定义的索引错误消息。我有一种感觉,客户端的GET没有正确发送url,或者如果是,它将值发送为null。

有人知道如何解决这个问题吗。客户端上的代码是:

<title>test</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{ 
  $.getJSON("process.php", function(fileName) 
{           
    for(var i in fileName)
    {
        fileName[i] = fileName[i].split("../Test/").join("")
        fileName[i] = fileName[i].split(".xml").join("")
        document.dropDown.file[i]= new Option(fileName[i],"../Test/"+fileName[i]+".xml", false)
    }       
});
});
var xmlhttp;
function getFile(str){
alert("xmlprocess.php?filename="+str);
if (str=="")
{
   document.getElementById("txtHint").innerHTML="";
   return;
} 
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= response(file);
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML= xmlhttp.responseText;
}
}
xmlhttp.open("GET","xmlprocess.php?filename="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form name = "dropDown">
<Select name = "file" onclick = "getFile(str1)" onchange = "str1 =    this.options[this.selectedIndex].value"></Select>
</form>
<div id="txtHint"></div>
</html>

服务器端的代码是:

<?php   
 ini_set('display_errors',1); 
 error_reporting(E_ALL);
$br = "<br>";
$filename = $_GET["filename"];
echo $filename;
?>

好的,伙计们,我找到了答案

我不得不将onreadystatechange更改为等于客户端的一个函数,如下所示

xmlhttp.onreadystatechange= function(){
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
   {
      document.getElementById("txtHint").innerHTML= xmlhttp.responseText;
   }
};