Welcome Guest, Not a member yet? Register   Sign In
Codeigniter + JQuery 1.4.2 + autocomplete
#11

[eluser]Blinkiz[/eluser]
Thanks Kyle for the easy guide to implement autocomplete.

Am having a problem. When I for example search for "Kyle", my browser tries to send this to
Code:
http://localhost/views/search/search_person_name/kyle?term=kyle
which does not exist. How can I change this so I get this url instead?
Code:
http://localhost/views/search/search_person_name/kyle
#12

[eluser]Kyle Ellman[/eluser]
I'm actually not sure. I think that if you keep get disabled, CI ignores it. I could be wrong about that, though. Mine works without trying to change it.

Sorry I can't be of any further help.
#13

[eluser]Blinkiz[/eluser]
Solution to my problem is to change
Code:
$config['uri_protocol']    = "AUTO";
to something like
Code:
$config['uri_protocol']    = "PATH_INFO";
in config.php. Then codeigniter will start to accept a string like
Code:
http://localhost/views/search/search_person_name/kyle?term=kyle
#14

[eluser]Blinkiz[/eluser]
I just wanted to share a working code that am using.
Don't forget to include the css file for the jquery ui in your header.

View
[removed] is the script tags for loading "data/jquery-1.4.3.min.js" and "data/jquery-ui-1.8.6.custom.min.js".
Much html code is removed to make it easier to read.

Code:
<div class="moduletable">
    &lt;form Method="POST" Action="&lt;?php echo site_url(); ?&gt;people/add" Name="addperson"&gt;
        <table>
            <tr>
                <td>
                    Person name<br />
                    &lt;input id="name" name="name" value="" /&gt;&lt;br />
                </td>
            </tr>
            </tbody>
        </table>
        &lt;/form&gt;
</div>
&lt;!-- javascripts --&gt;
[removed][removed]
[removed][removed]
[removed]
$(function() {
    $( "#name" ).autocomplete({
        source: '&lt;?php echo site_url('search/search_person_name/');?&gt;',
        search: function(event, ui)
        {
            $("#name").autocomplete("option", "source", "&lt;?php echo site_url('search/search_person_name/');?&gt;/"+$("#name").val());
        }
    });
});
[removed]
Controller
Code:
function search_person_name()
{
    echo json_encode($this->searchmodel->search_person_name($this->uri->segment(3)));
}
Model
Code:
function search_person_name($search)
{
    $query = $this->db->select('cp.id,cp.name')->from('contactpersons cp')->like('cp.name', $search)->get();
    foreach($query->result_array() as $name)
    {
        $data[] = array('label' => $name['name'], 'value' => $name['name'], 'id' => $name['id']);
    }
    return $data;
}




Theme © iAndrew 2016 - Forum software by © MyBB