Avi
Avi

Reputation: 31

autocomplete jquery

I am using a autocomplete jquery. Code I am suing is something like this:

 $(function() {          
        $( "#search").keyup(function(){
            var cat=$("#categoryTag option:selected").text();
            var url = "${resource.path}.suggestion.$"+this.value+".$"+cat+".json";
            $(this).autocomplete({               
                   source: url,
                   minLength: 2,
                   appendTo: "#search_results_div"
               });
        });

It is working fine, but The url I am getting is something like this http://servername/pagename/suggestion.textboxValue.dropdownValue?term=textBoxVale

My question is How can I avoid the query string as I want my url like this http://servername/pagename/suggestion.textboxValue.dropdownValue

Please give me pointers. Thanks in advance

Upvotes: 3

Views: 1908

Answers (1)

mak
mak

Reputation: 13405

source can be a callback in which you can ajax any url you want:

$("#search").autocomplete({
    source: loadFromAjax,
    minLength: 2,
    appendTo: "#search_results_div"
});

function loadFromAjax(request, response) {
    $.ajax({
        url: '/your/url/here/' + encodeURIComponent(request.term)),
        dataType: 'json',
        success: function(data) {
            // you can format data here if necessary
            response(data);
        }
    });
}

Upvotes: 1

Related Questions