通过result.php查">
当前位置:Gxlcms > PHP教程 > 通过ajaxPOST传值,但返回为空解决思路

通过ajaxPOST传值,但返回为空解决思路

时间:2021-07-01 10:21:17 帮助过:19人阅读

通过ajax POST传值,但返回为空
第一次接触ajax,想通过一个简单的例子来练练
index.php中有一个下拉列表,选择不同的班级返回不同的学生信息
代码如下:

	//从数据库把班级名称取出来放入下拉列表中
mysql_connect("localhost","root","root") or die("数据库连接失败");
mysql_select_db("studentmanage") or die("数据库不存在");

$sql="select * from class";
$rs=mysql_query($sql);
$info=array();
while($row=mysql_fetch_assoc($rs)){
$info[]=$row;
}

?>



查询学生信息







请选择班级:







通过result.php查询数据库,并返回学生信息,代码如下:
	//header("content-type:text/html;charset=utf-8");
header("Content-type:text/xml;charset=utf-8");
header("Cache-Control:no-cache");
$class=$_POST['class'];

mysql_connect("localhost","root","root") or die("数据库连接失败");
mysql_select_db("studentmanage");
mysql_query("set names utf-8");
$sql="select * from student where cid='$class'";
//$sql="select * from student where cid=3";
$rs=mysql_query($sql);
$info=array();
while($row=mysql_fetch_assoc($rs)){
$info[]=$row;
}

$result="";
foreach($info as $v){
$result.="";
}
$result.="
学号姓名住址班级
{$v['sid']}{$v['name']}{$v['address']}{$v['cid']}
";
echo $result;
?>


我单独测试了下result.php,我确定没有问题,能从数据库中取出对应的信息,但是就是不能把取到的信息返回到index.php中
求各位帮帮忙,找找问题在哪
------解决方案--------------------
给div设置value?即使你的查询时正常的,由于div的value并不会直接在视图中展现,所以你看不到效果。
你需要的应该是innerHTML

人气教程排行