0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

5 Comments

The problem is that the URL will be appended with ?term=value and that's what I need to change to /search/value
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.
damn, got the wrong link of autocomplete. Post updated, please check it out, thanks.
Did you tried what I have mentioned above? changing ajax type to 'post'?
I'm sorry, I gave the wrong link to the plugin. I am using this plugin: jqueryui.com/demos/autocomplete . Can this be done now ? The code is different, I can't find that line you mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.