使用jquery下拉列表

时间:2013-08-14 13:27:41

标签: php javascript ajax

我正在尝试将动态下拉框作为搜索工具,以帮助缩小mysql服务器的显示数据。我是一个体面的PHP程序员,但需要javascript和ajax的帮助 我使用下面的代码下载列表与ajax但是当从第一个列表框中选择一个药水时,下一个列表框中没有任何视图

请帮帮我?

ostan.php:
<head>
<script>

$(function (){ //document is loaded so we can bind events

  $("#ali").change(function (){ //change event for select
  $.ajax({  //ajax call
    type: "POST",      //method == POST 
    url: "getshahr.php", //url to be called
   data: { ali:  $("#ali option:selected").val()} //data to be send 
 }).done(function( msg ) { //called when request is successful msg
   //do something with msg which is response
         $("#txtHint").html(msg);  
     });
   });
 });

</script>
</head>

<?php
//db connection info.
$dbuser = 'root';

$dbhost = 'localhost';

$dbpass = '';

$dbname = 'tutorial';

$mysql_link = mysql_connect($dbhost,$dbuser,$dbpass) or die ("Could not connect");     

mysql_select_db ($dbname) or die ("DB select failed"); //select db

$query = "select DISTINCT ostan from com"; //get product count by groups of products

$result = mysql_query($query); //queryresult1
echo '<select id="ali">';
while($row = mysql_fetch_array($result))
{

  echo '<option id="'.$row['ostan'].'">'.$row['ostan'].'</option>';



}echo "</select><br /><br ><div id=\"txtHint\"><select name='select'>
 <option>Select City</option>
 </select></div>";

?>





getshahr.php:

<?php
//db connection info.
$dbuser = 'root';
$dbhost = 'localhost';
$dbpass = '';
$dbname = 'tutorial';
$mysql_link = mysql_connect($dbhost,$dbuser,$dbpass) or die ("Could not connect");    

mysql_select_db ($dbname) or die ("DB select failed"); //select db
$query = "select shahr from com where ostan='{$_POST["ali"]}'";       
$result = mysql_query($query); //queryresult1
echo '<select id="ali">';
while($row = mysql_fetch_array($result))
{
  echo '<option id="'.$row['shahr'].'">'.$row['shahr'].'</option>';
}
echo "</select><br /><br />";

?>

0 个答案:

没有答案
相关问题