JavaScript 中的 alert(status) 总是导致 null


alert(status) in javascript always results in null

>我有一个php页面,我想从我选择的下拉列表中给我动态结果。有关所选选项的详细信息保存在数据库中。因此,基本上是在我选择一个选项时动态地从数据库中获取详细信息。

我从中选择数据的第一页(这里的数据是事件)

<form name="ParticularFest" action="" method="post">
<table align="center">
<tr>
<tr><td><br/></td></tr>
<td><h4>Fest Name: </h4></td>
<td>
<select name="EventId" id="EventId" onchange="javascript: return ParticularValidate();"><option>Select Event</option>
<?php
$sql="Select EventName,MEventId from Tbl_Main where Status=0 and CategoryId=1";
$stmnt=sqlsrv_query($conn,$sql);
while( $row = sqlsrv_fetch_array( $stmnt,SQLSRV_FETCH_BOTH)) 
{
echo'<option value="'.$row["MEventId"].'">'.$row["EventName"].'</option>';
}
?>
</select>
</td>
</tr>
</table>
<div id="display"></div>
</form>
<script type="text/javascript">
function ParticularValidate() {
  var errorMessage = null;
  var MEventId = document.ParticularFest.EventId.value
  var status = null;
  if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
    //alert("firefox");
  } else { // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      status = xmlhttp.responseText;
      document.ParticularFest.display.innerHTML = status;
    }
  }
  xmlhttp.open("GET", "ParticularValidate.php?MEventId=" + MEventId, true);
  xmlhttp.send();
}
</script>

下一页是我要重定向到的页面,即 SpecificValidate.php

<?php
include_once("Db.php");
$MEID=$_REQUEST['EventID'];
$obj=new Db;
?>
<table align="center">
<tr>
<th width="200" align="center"><br/><h3><b>Program Name</b></h3></th>
<th width="340" align="center"><br/><h3><b>Name</b></h3></th>
<th width="200" align="center"><br/><h3><b>Mobile No.</b></h3></th>
<th width="200" align="center"><br/><h3><b>Email</b></h3></th>
<th width="200" align="center"><br/><h3><b>College Name</b></h3></th>
<tr><td><br></td></tr>
</tr>
<?php
$sql="select distinct na.ProgramName,ma.Name,ma.Mob,ma.Email,ma.CName from Tbl_Main as sa inner join Tbl_UserProgram as ra on sa.MEventId=ra.EventId inner join Tbl_UserReg as ma on ma.UserId=ra.UserId inner join Tbl_Program as na on ra.PgmId=na.ProgramId and sa.MEventId='$MEID'";
$stmnt=sqlsrv_query($conn,$sql);
while($row = sqlsrv_fetch_array($stmnt,SQLSRV_FETCH_BOTH)) 
{
echo
'<tr align="center">
<td>'.$row["ProgramName"].'</td>
<td>'.$row["Name"].'</td>
<td>'.$row["Mob"].' </td>
<td>'.$row["Email"].'</td>
<td>'.$row["CName"].'</td>
<tr><td><br></td></tr>
</tr>';
}
?>
</table>

两者都另存为.php

从数据库获取的数据(选择查询)在数据库查询中工作正常。

状态始终为空。

我试图查看状态是否正在获取数据,是否仅仅是显示部分,这就是问题所在。但这些结果总是 Null。我是这些菜鸟,所以请给我建议。

提前谢谢你。

编辑 1:我试图检查这是否:

var MEventId=document.ParticularFest.EventId.value

正在获取MEventId,是的。它也在发送MEventId。问题似乎出在第二个 php 页面中。我没有从该页面获得任何回报。(我在第一个 php 页面的几乎所有地方都尝试了警报(状态),它显示空弹出窗口总是:D)

编辑 2:这是在本地主机中完成的。这是一个大学迷你项目

请求完成之前,警报会立即发生。

尝试这样的事情。

<script type="text/javascript">
(function() {
  var httpRequest;
  document.getElementById("ajaxButton").onclick = function() { makeRequest('test.html'); };
  function makeRequest(url) {
    httpRequest = new XMLHttpRequest();
    if (!httpRequest) {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false;
    }
    httpRequest.onreadystatechange = alertContents;
    httpRequest.open('GET', url);
    httpRequest.send();
  }
  function alertContents() {
    if (httpRequest.readyState === XMLHttpRequest.DONE) {
      if (httpRequest.status === 200) {
        alert(httpRequest.responseText);
      } else {
        alert('There was a problem with the request.');
      }
    }
  }
})();
</script>