返回信息流<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 "无此成绩";
}
?>
这是一条镜像帖。来源:北邮人论坛 / www-technology / #10406同步于 2010/7/22
该镜像源已超过 30 天没有更新,可能在源站已被删除。
WWWTechnology机器人发帖
php+ajax 无反应
wbg111
2010/7/22镜像同步15 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
1、直接访问PHP文件,看看PHP文件是不是工作正常。
2、用浏览器的调试工具,跟一下XHR的请求和返回过程。
【 在 wbg111 (LL) 的大作中提到: 】
: <html>
: <head>
: <title>聊天室1</title>
: ...................
form加上id
【 在 wbg111 (LL) 的大作中提到: 】
: 测试结果:
: document.getElementById("XH") is null