后台用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标签都删除了)
<?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标签都删除了)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货