所以,这里是问题:
我正在尝试处理传递 ID 字段的 PHP 文件中的一些编辑。PHP 文件正在成功构建 HTML 页面并显示它,但嵌入的 javascript 调用的某些部分无法正常工作。
如果我注释掉调用 echo ' xmlhttp.onreadystatechange=function(){'; 我收到所有警报。
一旦我取消注释 xmlhttp.onreadystatechange=function() 块,什么都不起作用。
任何帮助将不胜感激 - 以下是完整的代码块:
echo '<script type="text/javascript">';
echo 'function populateRoomDropDown(building)';
echo '{';
echo ' alert("Started...");';
echo ' if(window.XMLHttpRequest){';
echo ' xmlhttp = new XMLHttpRequest();';
echo ' alert("Building ID: "+building);';
echo ' }';
echo ' else{';
echo ' xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");';
echo ' alert("IE Browser");';
echo ' }';
echo ' xmlhttp.onreadystatechange=function(){';
echo ' alert("Inside onready...()");';
echo ' if (xmlhttp.readyState==4 && xmlhttp.status==200){';
echo ' alert("Inside onready...()");';
echo ' document.getElementById("displayRooms").innerHTML=xmlhttp.responseText;';
echo ' }';
echo ' }';
echo ' alert("Near end...");';
echo ' xmlhttp.open("GET","../db_queries/getRoomsDropDown.php?buildingID="+building,true);';
echo ' xmlhttp.send();';
echo ' alert("End...");';
echo '}';
echo '</script>';