jquery posting to php file -
trying jquery code post value php file have, , return array of data.
the basic idea search database, fill bootstrap's typeahead value. working in codeigniter.
search controller:
<?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 $row){ $data = $data . "<div>" . $row->mobile_number . "</div>"; } echo $data; } } } jquery fills typeahead:
<script> //searches database mobile numbers $(function() { var searchitem = $("#typeahead").val(); var itemsarray = [ "1111111111", "2222222222", "3333333333" ]; //push search controller, receive array of mobile numbers match $("#typeahead").typeahead({ source: itemsarray }); }); </script> so, i'm not sure how post value of search box php, how format when returned. thoughts? pretty new of this. not sure possible. appreciated.
$.ajax, $.post , $.getjson of many jquery functions out there.
Comments
Post a Comment