jquery发布到php文件
尝试获取一些jquery代码,将值发布到我拥有的php文件中,并返回一个数据数组 基本思想是搜索数据库,然后用值填充bootstrap的typeahead。在CodeIgniter中工作 搜索控制器:jquery发布到php文件,php,jquery,codeigniter,Php,Jquery,Codeigniter,尝试获取一些jquery代码,将值发布到我拥有的php文件中,并返回一个数据数组 基本思想是搜索数据库,然后用值填充bootstrap的typeahead。在CodeIgniter中工作 搜索控制器: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Search extends CI_Controller { public function index() { }
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Search extends CI_Controller {
public function index()
{
}
public function getSearchResults()
{
$partialSearch = $_POST['partialSearch'];
if (strlen($partialSearch) > 5) {
$this->db->select('mobile_number');
$this->db->like('mobile_number', $partialSearch);
$query = $this->db->get('phone_lines');
$result = $query->result();
$data = "";
foreach($result as $row){
$data = $data . "<div>" . $row->mobile_number . "</div>";
}
echo $data;
}
}
}
$.ajax
、$.post
和$.getjson
是众多jQuery函数中的一部分。第一个函数你运气好吗?我想我们需要在meta上提出一个问题,使搜索框大300%。
<script>
//searches the database for mobile numbers
$(function() {
var searchItem = $("#typeahead").val();
var itemsArray = [
"1111111111",
"2222222222",
"3333333333"
];
//push to search controller, receive back array of mobile numbers that match
$("#typeahead").typeahead({
source: itemsArray
});
});
</script>