BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / www-technology / #10406同步于 2010/7/22
该镜像源已超过 30 天没有更新,可能在源站已被删除。
WWWTechnology机器人发帖

php+ajax 无反应

wbg111
2010/7/22镜像同步15 回复
<html> <head> <title>聊天室1</title> <script> function GetXmlHttpObject() { var xmlHttp=null; try{ xmlHttp=new XMLHttpRequest(); } catch(e){ try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlHttp; } function cj_query() { xmlHttp=GetXmlHttpObject(); var XH = document.getElementById("XH").value; var KCM = document.getElementById("KCM").value; var url="EX_9_1_process.php"; url=url+"?XH="+XH+"&KCM="+KCM; url=url+"&sid="+Math.random(); xmlHttp.open("GET",url,true); //xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.send(null); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4&&xmlHttp.status==200) { document.getElementById("CJ").value=xmlHttp.responseText; } } } </script> </head> <body> <form action=""> 学号:<input type="text" name="XH" size="12"> 课程号:<input type="text" name="KCM" size="12"> <input type="button" value="查询" onclick="cj_query();"><br> 成绩:<input type="text" name="CJ" size="12"> </form> </body> </html> EX9_1_process.php <?php $XH=$_GET["XH"]; $KCM=$_GET["KCM"]; //echo "ok"; $conn=mysql_connect("localhost","root","YES"); mysql_select_db("pxscj",$conn)or die('数据库连接失败'); mysql_query("SET NAMES gb2312"); $sql="select 成绩 from cjb where 学号='$XH' and 课程号='$KCM'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); if($row) { echo $row['成绩']; } else { echo "无此成绩"; } ?>
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
BookMoth机器人#1 · 2010/7/22
1、直接访问PHP文件,看看PHP文件是不是工作正常。 2、用浏览器的调试工具,跟一下XHR的请求和返回过程。 【 在 wbg111 (LL) 的大作中提到: 】 : <html> : <head> : <title>聊天室1</title> : ...................
wbg111机器人#2 · 2010/7/22
1.是正常的 2.怎么用浏览器的调试工具?
DestinyOwner机器人#3 · 2010/7/22
IE8或火狐 F12 【 在 wbg111 (LL) 的大作中提到: 】 : 1.是正常的 : 2.怎么用浏览器的调试工具?
wbg111机器人#4 · 2010/7/22
好的,我先试试,谢谢咯,O(∩_∩)O哈哈~
dickfu机器人#5 · 2010/7/22
不装firebug也能f12?? 【 在 DestinyOwner (爱荷散人|奋斗ing) 的大作中提到: 】 : IE8或火狐 F12
ox机器人#6 · 2010/7/22
装个Firebug吧。。。巨好用 【 在 wbg111 (LL) 的大作中提到: 】 : 1.是正常的 : 2.怎么用浏览器的调试工具?
ericyosho机器人#7 · 2010/7/22
getElementById 是说一定要有id么?你给那两个node,加上id的属性试试?
wbg111机器人#8 · 2010/7/22
测试结果: document.getElementById("XH") is null
xw2423机器人#9 · 2010/7/22
form加上id 【 在 wbg111 (LL) 的大作中提到: 】 : 测试结果: : document.getElementById("XH") is null