views:

51

answers:

3

Hello, I'm using this plugin: http://jqueryui.com/demos/autocomplete/#remote

Works great but I would like to use the request URL like this: "www.mysite.com/search/my search input" and not like this: "www.mysite.com/?term=my search input" because I use codeigniter and that's how I work with URLs. So I will need to append the search input like this "/my search input" because I can give the first part of the URL but I don't know how can I change the appending of "?term=" .

The problem is that the URL will be appended with ?term=value and that's what I need to change to /search/value. Codeigniter is not an issue here, the autocomplete code needs changes, I believe.

Any ideas ?

Thanks.

A: 

Hi,

You can use the codeigniter URLs directly in the autocomplete's URL parameter. I used the below one in one of my projects.

<script>
$(document).ready(function(){
    $("#search").autocomplete('<?php echo site_url('ajax/get_words');?>', {
            extraParams: {
               language: function() { return 'english'; }
           }
        });
});
</script>

I hope this will help you. Let me know if you need more.

Abu Sithik
The problem is that the URL will be appended with ?term=value and that's what I need to change to /search/value
Manny Calavera
If you see in my code I have added the additional parameter `language`. You can also add your parameters like this. And MOST IMPORTANTLY by default jQuery autocomplete will send additional parameters in GET variables like ?term=value. You should change the default ajax type to 'post' in the `$.ajax({ type:` in jquery.autocomplete.js file around line no. 330 to 340.
Abu Sithik
damn, got the wrong link of autocomplete. Post updated, please check it out, thanks.
Manny Calavera
Did you tried what I have mentioned above? changing ajax type to 'post'?
Abu Sithik
I'm sorry, I gave the wrong link to the plugin. I am using this plugin: http://jqueryui.com/demos/autocomplete/ . Can this be done now ? The code is different, I can't find that line you mentioned.
Manny Calavera
Managed to do it myself, thank you for your interest.
Manny Calavera
A: 

I managed to work this out with this code:

$( "#test" ).autocomplete({
            source: function(req, add){
                $.ajax({
                    url: 'search/q',
                    dataType: 'json',
                    type: 'POST',
                    data: req,
            success:function(data){
                var items = [];  
                $.each(data, function(i, val){  
                items.push(val);  
                });  
                add(items);
                }
                })
                },
            minLength: 2,
            autoFill:true,
            highlight:true,
            scroll:true,
            selectFirst:true,
            matchContains: true
        });

I hope this come in handy if anyone is in search of the same thing.

Manny Calavera
A: 

Thanks Manny, you solved my problem with CI too :)

john
I'm glad it helped you. You should write this kind of message on the "add comment" function on my answer, not as an answer itself, I believe. Cheers :)
Manny Calavera