CodeIgniter自动完成多个字段无法正常工作

时间:2014-05-27 05:34:25

标签: php jquery codeigniter

Codeigniter自动完成功能不正常。 当我在文本文件中输入时,它没有显示自动完成列表。我没有得到我犯错误的地方。这是我的代码。

这是我的浏览页面。

    <!doctype html>
        <html> 
            <head> 
            <title>test jquery autocomplete</title> 
            <script type="text/javascript" src="<?php echo base_url();?>jquery/js/jquery-1.4.2.min.js"></script> 
            <script type="text/javascript" src="<?php echo base_url();?>jquery/js/jquery-ui-1.8.2.custom.min.js"></script> 
            <script type="text/javascript"> 

                jQuery(document).ready(function(){
                    $('#zipsearch').autocomplete({
                               source:'<?php echo base_url();?>/management/get_materials', minLength:2,
                        select:function(evt, ui)
                {

                    // when a zipcode is selected, populate related fields in this form
                    this.form.city.value = ui.item.city;
                    this.form.state.value = ui.item.state;
                }


                });
                });

            </script> 
            <link rel="stylesheet" href="<?php echo base_url();?>jquery/css/smoothness/jquery-ui-1.8.2.custom.css" /> 
            <style type="text/css"><!--

                    /* style the auto-complete response */
                    li.ui-menu-item { font-size:12px !important; }

            --></style> 
        </head> 

        <body> 

        <form onsubmit="return false;"> 
            Enter a Zipcode:
            <input id='zipsearch' type="text"/> 
                Enter a City:
            <input name="city" id="city1" type="text" /> 
            Enter a State:
            <input name="state" id="state1" type="text" /> <br/>



        </form> 

        </body> 
        </html>

这是我的控制器

    public function get_materials()
    {
    $data=$this->user_model->get_materials();
    echo json_encode($data);
    flush();
    }

这是我的模特

  public function get_materials()
 {
      if ( !isset($_REQUEST['term']) )
      exit;
      $rs = mysql_query('select zip, city, state from zipcode where zip like "'. mysql_real_escape_string($_REQUEST['term']) .'%" order by zip asc limit 0,10');
      $data = array();
      if ( $rs && mysql_num_rows($rs) )
      {
          while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
          {
              $data[] = array(
                  'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] ,
                  'value' => $row['zip']
              );
          }
      }
return $data;

}

自动列表未显示。我没有得到我犯错误的地方。请帮帮我们。

0 个答案:

没有答案
相关问题