0

I am using:

$( "#search" ).autocomplete({
      source: "http://ztest.local/ajax/ac"
    });

So if a user types in the search box, a request is sent to the server...problem is I would like the format to be of the form:

http://ztest.local/ajax/ac/term/foo

However the request is given as:

http://ztest.local/ajax/ac?term=foo

I have tried:

source: 'http://ztest.local/ajax/ac/term/' + encodeURIComponent($('#search').val()

however that didn't even make a request...

Not sure how to move forward, somewhat related question

1 Answer 1

1

I used JQuery-Autocomplete with Zend for a project couple of months ago. Here is how I wrote up the source, hope it helps.

 $( "#unit_autocomplete" ).autocomplete({
        source: function( request, response ) {     
            $.ajax({
                url: 'http://localhost/becasPropias/public/unit/autocomplete/format/json'+
                     '/type/'+type+'/term/'+request.term,
                dataType: "json",
                success: function( data ) {
                    $("#unit_autocomplete").removeClass('ui-autocomplete-loading');
                },
                error: function(jqXHR, textStatus, errorThrown ){
                    $("#unit_autocomplete").removeClass('ui-autocomplete-loading');
                } 
            });
        },
        minLength:2,
        select: function(event, selectedItem) {
            toggle('hidden_unit', selectedItem['item']);
        },
        open: function() {
            $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
        },
        close: function() {
            $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
        }
    });

Out of this whole code, here is the part that interests you:

source: function( request, response ) {     
            $.ajax({
                url: 'http://localhost/becasPropias/public/unit/autocomplete/format/json'+
                     '/type/'+type+'/term/'+request.term,
                dataType: "json",
                success: function( data ) {
                    $("#unit_autocomplete").removeClass('ui-autocomplete-loading');
                },
                error: function(jqXHR, textStatus, errorThrown ){
                    $("#unit_autocomplete").removeClass('ui-autocomplete-loading');
                } 
            });
        }

And out of this code

    url: 'http://localhost/becasPropias/public/unit/autocomplete/format/json'+
                     '/type/'+type+'/term/'+request.term,

As you see, you can put in the url as you need. The code for this is available in my git account.

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

Comments

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.