用Codeigniter和jquery撕裂我的头发。jQuery与Codeigniter的自动完成,不能在索引函数外工作
我有一个非常基本的代码集来解决这个问题。
目前我的索引函数调用了我的视图。该视图完全处理jquery自动完成与这种情况。
如果我将索引更改为indextest或自动完成功能停止工作的任何其他名称。几乎就像jquery输出正在被专门传递给页面的默认方法,被index.php。
有没有办法指定方法是必须返回还是显示?
我的控制器:
<?Php
class Sales extends MY_Controller{
function __construct() {
//call parent constructor
parent::__construct();
$this->load->model('sales_model');
}
function index(){
$this->load->view('sales/new_order_details');
}
function get_customers(){
$this->load->model('Sales_model');
if (isset($_GET['term'])){
$q = strtolower($_GET['term']);
$this->Sales_model->get_customer($q);
}
}
function login() {
redirect('/pointer/login');
}
function logout() {
redirect('/pointer/logout');
}
}
我的模型
<?php
// (Array of Strings)
class Sales_model extends MY_Model{
function get_customer($q){
$this->db->select('CustomerName');
$this->db->like('CustomerName', $q);
$query = $this->db->get('Customers');
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['CustomerName'])); //build an array
}
echo json_encode($row_set); //format the array into json data
}
}
}
我查看
<html>
<head>
<title>
Capture New Order
</title>
<link href="<?php echo base_url() ?>application/css/ui-lightness/jquery-ui-1.8.custom.css" media="screen" type="text/stylesheet" rel="stylesheet">
<script src="<?php echo base_url() ?>application/scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>application/scripts/jquery-ui-1.10.1.custom.min.js" type="text/javascript"></script>
<script src="<?php echo base_url() ?>application/scripts/autocomplete.js" type="text/javascript"></script>
</head>
<body>
<div data-role="page" data-theme="a">
<div class="wrap-header">
<div data-role="header" data-mini="true" data-ajax="false">
<a data-icon="grid" data-mini="true" data-theme="a" onclick="window.location.href='/pointer'">Menu</a>
<h3>New Order Details</h3>
</div>
</div>
<div data-role="content">
<form>
<label for="customer">Customer</label>
<input type="text" id="customer" />
</form>
</div>
</body>
</html>
autocomplete.js
$(function(){
$("#customer").autocomplete({
source: "sales/get_customers"
});
});
所以如前所述,如果我改变指数()控制器的方法indextest(),并直接浏览到方法的自动完成停止工作。
我是否缺少一些简单的东西或者是否有更大的理由让我无法解决?
感谢一如既往的帮助,
UPDATE AS PER FABIO 从谷歌Chrome浏览器开发的输出上调用自动完成脚本
正常指数()工作)
indextext ()
我第一次拍摄是 “销售/ get_customers” 遗漏的这一请求。检查浏览器是否发送请求并从服务器获取响应。 – Saram 2013-03-13 10:14:57
谢谢Saram,我可以请你引导我检查浏览器发送和响应文件。我确实有firebug和铬的firefox。再次感谢。 – Smudger 2013-03-13 10:32:09
我可以看到你有答案,你的屏幕显示了我的意思 - 查找源错过。 – Saram 2013-03-13 11:54:43