ThinkPHP +AJAX 联动从数据库无刷新提取数据,显示在页面的下拉框时出错!

来源:互联网 发布:linux服务器维护手册 编辑:程序博客网 时间:2024/04/30 07:07

错误是这样的,只要点击选择省的下拉框后,就会显示出这些文字,请问怎么才能消除这一问题呢



控制器代码

 function show_ss(){
            $area =M("Area");       
            $privince = $area->where("region_type = 1")->select();
            
            $this->assign("privince",$privince);                    
            $provincecode=$_GET['provincecode'];//接收省键值
            $citycode=$_GET['citycode'];//接收城市键值
            if($provincecode !=""){
            $citys=$area->where("parent_id='$provincecode'")->select();
            echo "<select name='area[]' onchange='queryArea(this.options[this.selectedIndex].value)'>";
            echo "<option value='-1' selected>请选城市</option>n";
                foreach ($citys as $key=>$val ){
             echo "<option value='{$citys[$key]['region_id']}'>{$citys[$key]['region_name']}</option>";
               }
            }
            if($citycode!=""){
            $areas=$area->where("parent_id='$citycode'")->select();
            if(!empty($areas)){
            echo "<select name='area[]'>n";
            echo "<option value='-1' selected>请选择县</option>n";
               foreach ($areas as $key=>$val ){
            echo "<option value='{$areas[$key]['region_id']}'>{$areas[$key]['region_name']}</option>";
                }
                echo "</select>n";
            }else{
            $areaname =$area->where("region_id ='$citycode'")->field('region_name')->find();
            echo "<select name='area[]'>n";
            echo "<option value='-1' selected>请选择县</option>n";
            echo "<option value='{$areaname['region_name']}' selected>{$areaname['region_name']}</option>";
            echo "</select>n";
            }
            }

/*html显示代码*/
<dt>地区:</dt>
<div class="info">
    
    <select name="area[]" onchange='queryCity(this.options[this.selectedIndex].value)'>
    <option value="0">请选择地区</option>
        <foreach name="privince" item="vo">
        <option value="{$vo.region_id}" class="temo">{$vo.region_name}</option>
        </foreach>
        
    </select>
    <span id='city'></span>&nbsp;
    <span id='area'></span>  
    
    
</div>





/*.js代码*/
var xmlHttp;
  var requestType="";
  function createXMLHttpRequest()
  {
      if(window.ActiveXObject)
      {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      else if(window.XMLHttpRequest)
      {
          xmlHttp=new XMLHttpRequest();
      }
  }

  function handleStateChange(){
      if(xmlHttp.readyState==4)
          {
          if(xmlHttp.status==200)
              {
              if(requestType=="city"){
                                  showcity();
                              }
              else if(requestType="area"){
                                      showarea();
                                  }
              }
          }
  }
  function queryCity(citycode){
      createXMLHttpRequest();
      requestType="city";
      var url="http://web.2015f.com/winner/index.php/Home/Goods/show_ss/provincecode/"+citycode+"/"+Math.random();
      xmlHttp.open("GET",url,true);
      xmlHttp.onreadystatechange=handleStateChange;
      xmlHttp.send(null);
     
  }

  function queryCity(citycode){
      createXMLHttpRequest();
      requestType="city";
      var url="http://web.2015f.com/winner/index.php/Home/Goods/show_ss/provincecode/"+citycode+"/"+Math.random();
      xmlHttp.open("GET",url,true);
      xmlHttp.onreadystatechange=handleStateChange;
      xmlHttp.send(null);
     
  }

  function queryArea(citycode){
      createXMLHttpRequest();
      requestType="area";
      var url="http://web.2015f.com/winner/index.php/Home/Goods/show_ss/citycode/"+citycode+"/"+Math.random();
      xmlHttp.open("GET",url,true);
      xmlHttp.onreadystatechange=handleStateChange;
      xmlHttp.send(null);
  }
  function showcity(){
    document.getElementById("city").innerHTML=xmlHttp.responseText;//捕获ID显示返回的数据
  }
  function showarea(){
      document.getElementById("area").innerHTML=xmlHttp.responseText;//捕获ID显示返回的数据
  }

0 0
原创粉丝点击