Javascript 将Ajax与Codeigniter结合使用

Javascript 将Ajax与Codeigniter结合使用,javascript,php,jquery,ajax,codeigniter,Javascript,Php,Jquery,Ajax,Codeigniter,我看了几页,但都试过了,没有一页对我有用 这就是我想要的: 在我的html上: <form class="form-horizontal" role="form" method="POST" action=""> <select name="customer_id" id="customer_id" class="form-control"> <option>Select custom

我看了几页,但都试过了,没有一页对我有用

这就是我想要的:

在我的html上:

<form class="form-horizontal" role="form" method="POST" action="">
                  <select name="customer_id" id="customer_id" class="form-control">
                    <option>Select customer</option>
                    <?php foreach($customers AS $customer): ?>
                      <option value="<?php echo $customer->id;?>"><?php echo $customer->name; ?></option>
                    <?php endforeach; ?>
                  </select>
                </div>
              </div>
              <div class="form-group">
                <label for="category" class="col-xs-4 control-label">Category</label>
                <div class="col-sm-4 col-xs-8">
                  <input type="text" class="form-control" name="category" id="category" placeholder="Category" disabled="disabled">
                </div>
              </div>
在我的模型上,我有:

public function getCustomerCat($id){
    $query ="SELECT category FROM customers WHERE id=$id";
    $query = $this->db->query($query);
    return $query->result();
}

我不太擅长ajax,但希望在选择客户后填充categoory字段,而不重新加载页面。

您是否收到ajax请求返回的错误或数据?使用firebug或chrome developer工具查看数据库是否返回或出现错误。使用firebug,您应该可以在控制台上看到ajax调用和返回,在Chrome开发工具中,它位于网络选项卡下。我收到一个语法错误“SyntaxError:missing}after property list”可能是一个过多的)};'s?@nWollybug谢谢我现在可以用了
public function getCustomerCat(){
$id = $this->input->post('customer_id');
$category = $this->customer_model->getCustomerCat($id)[0]->category;

echo $category;

}
public function getCustomerCat($id){
    $query ="SELECT category FROM customers WHERE id=$id";
    $query = $this->db->query($query);
    return $query->result();
}