php ajax动态读取的级联菜单 联动菜单

来源:互联网 发布:中国国产狙击步枪 知乎 编辑:程序博客网 时间:2024/05/17 03:51

01.php

<?php include("config.php");?><script src="http://www.freejs.net/js/jquery-1.9.1.min.js"></script><form action="02.php" name="form" id="form" method="post"  enctype="multipart/form-data">        <div class="both">          <h4>选择省份</h4>          <select name="search_category"  id="search_category_id">          <option value="" selected="selected"></option>          <?php  $sql_saleinfo = "SELECT * FROM data_type where flid=1 order by uid desc";$rs_saleinfo = mysqli_query($conn, $sql_saleinfo);while($rows = mysqli_fetch_assoc($rs_saleinfo)) { ?>              <option value="<?php echo $rows['id'];?>"><?php echo $rows['title'];?></option>          <?php          }?>          </select>             </div>            <div class="both">          <h4 id="show_heading">选择城市</h4>          <div id="show_sub_categories" align="center">              <img src="http://www.freejs.net/demo/281/loader.gif" style="margin-top:8px; float:left" id="loader" alt="" />          </div>      </div>      <br clear="all" /><br clear="all" />            <input type="submit" name="" value="GO" />  </form>  <script type="text/javascript">    $(document).ready(function() {        $('#loader').hide();      $('#show_heading').hide();            $('#search_category_id').change(function(){          $('#show_sub_categories').fadeOut();          $('#loader').show();          $.post("get_chid_categories.php", {              parent_id: $('#search_category_id').val(),          }, function(response){                            setTimeout("finishAjax('show_sub_categories', '"+escape(response)+"')", 400);          });          return false;      });  });    function finishAjax(id, response){    $('#loader').hide();    $('#show_heading').show();    $('#'+id).html(unescape(response));    $('#'+id).fadeIn();  }     function alert_id()  {      if($('#sub_category_id').val() == '')      alert('Please select a sub category.');      else      alert($('#sub_category_id').val());      return false;  }    </script>

get_chid_categories.php

<?php    include("config.php");  if($_REQUEST)  {      $id     = $_REQUEST['parent_id'];     // $query = "select * from ajax_categories where pid = ".$id;    //  $results = mysql_query( $query);$sql_saleinfo = "SELECT * FROM data_type where pid ='$id' order by uid desc";$rs_saleinfo = mysqli_query($conn, $sql_saleinfo);?>            <select name="sub_category"  id="sub_category_id">      <option value="" selected="selected"></option>      <?php      while($rows = mysqli_fetch_assoc($rs_saleinfo))     {?>          <option value="<?php echo $rows['title'];?>  ID=<?php echo $rows['id'];?>"><?php echo $rows['title'];?></option>      <?php      }?>      </select>           <?php     }  ?>  


02.php 代码

<meta charset="utf-8"><?php    echo $_POST['sub_category'];?>  




引用:http://www.freejs.net/demo/281/index.php

原创粉丝点击