后台用php,简单的数据库查询然后返回相应列的问题,代码如下:
<?php
require('connection.php');
$tb_name="img";
$sql="select * from $tb_name";
$result=mysql_query($sql,$link);
while($rows=mysql_fetch_array($result))
echo $rows["img_id"];
?>
前台html中javascript代码:
function img()
{
var option=document.getElementById("img_head");
var url="img_show.php";

try{
var xmlhttp=new XMLHttpRequest();
}catch(e){
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
var select1=xmlhttp.responseText;
while(option.options.length>0)
{
option.options.remove(0);
}
for(var j=0;j<select1.length;j++)
{
var coption=document.createElement("option");
coption.text=select1[j];
coption.value=select1[j];
option.add(coption);
}

}
}
xmlhttp.open("GET",url,true);
/*=========================================对于post传递方法必不可少===================*/
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
/*===================================================================================*/
xmlhttp.send();
}
为什么在输出的时候加上了html标签(强调我的php后台把多余的html标签都删除了)

解决方案 »

  1.   

    输出什么标签了 难道是  option
      

  2.   

    url加個隨機參數再試試,是不是有緩存
      

  3.   

    问题发现了原来是请求的require('connection.php');中里面的<html><head></head>……</html>没有删除,但是郁闷了,我其他页面请求connection.php就没有返回<html><head></head>……</html>,还有在调试的过程中我发现,firefox浏览器真是不怎么好用,总感觉有缓存似的每次修改完代码以后总还是出现上次的结果。
      

  4.   

    再继续请教一个问题,如何在点击提交按钮(submit)的时候如果页面有错误,如何防止跳转到form中action属性的后台页面?