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>
相关文章:
- html+javascript:如何在某些条件下禁用dropdownlist中的null选项
- 为什么是文档.旧版应用程序中的DOM-object.properties为null
- ASP.net Javascript函数中的隐藏字段为null
- 访问托管Bean中的ApplicationModule(FacesContext NULL)
- JavaScript中的RegExp返回null
- AJAX请求中的JSON对象为Null或空
- 如何确定Javascript数组中的字段是空的还是null
- 添加到序列化数组中的复杂对象在服务器端始终为 null
- 什么是 ClojureScript 类似地将不存在的对象值设置为 JavaScript 中的 null
- Javascript:将类/对象引用设置为 NULL,内存中的子对象/类会发生什么
- Javascript 中的 RegEx 返回 Null
- 未捕获的类型错误:无法调用方法'shift'Chrome中的Facebook JS库为null
- src为null的iframe中的Javascript文件的路径
- JavaScript:for循环中的集合为null
- Ajax调用后控制器中的参数为Null
- 从aspx.cs页面获取jquery post中的Null响应而不是json
- Don'如果“不希望发送电子邮件”;Null”;单元格中的值
- 失败:切换弹出窗口时,条目中的null值:name=null错误
- 如何删除javascript中的节点,而不需要父节点为null
- Angular HTTP GET 与 TypeScript 错误 http.get(..).映射不是 [null] 中的