.append在调用php文件时不工作

时间:2012-04-27 12:27:47

标签: php html jquery

我有这个曾经工作的功能,但显然决定对我进行转储。有没有人知道可能出现什么问题?

<?php 
require("php/connect.php");
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Clasificados</title> 
<link rel="stylesheet" href="css/index.css"/>
<link type="text/css" href="css/excite-bike/jquery-ui-1.8.19.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.19.custom.min.js"></script>
<script type="text/javascript">

$(function() {
    $.post(
        'php/bridge.php', 
        {
            fun:"estados"
        },
        function(answer){
            if(answer){
                $('#estafil').append(answer);
            }
        }
    );

});


</script>
</head>
<body>
<div id="left">
<form name="search">
    <fieldset>
        <label for="searchbar">Introduce terminos de busqueda:</label>
        <input type="text" name="searchbar" id="searchbar" class="text ui-widget-content ui-corner-all" />
        <label for="estafil">Filtrar por estados:</label>
        <select name="estafil" id="estafil" class="text ui-widget-content ui-corner-all" >
        </select>
        <input type="submit" value="Inciciar busqueda" />
    </fieldset>
</form>
</div>
</body>

调用的php是这样的:

require("connect.php");
session_start();
$fun=$_POST['fun'];
$rol=$_SESSION['rol'];
$id=$_SESSION['id'];
if($fun=="estados"){
   $query="SELECT Nombre FROM estados";
   $extract=mysql_query($query) or die(mysql_error());
   while($row = mysql_fetch_assoc($extract)){
       echo $row['Nombre'];
   }
}

我已经尝试了一切,但我真的无法确定问题!

1 个答案:

答案 0 :(得分:2)

您正在返回文字。请尝试此代码

   while($row = mysql_fetch_assoc($extract)){
        echo '<option>'.$row['Nombre'].'</option>';
    }