Question

I'm trying to write a JQuery autocomplete script which will call a url via AJAX and update autocomplete results as user enters data into the form.

I have my AJAX setup and currently returning JSON. But I don't know how to go about getting the autocomplete function to call it and use the response. I have managed to get the following working, but this is static data, so no good for my task:

$("input#name").autocomplete({
        source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
});

Cheers.

Was it helpful?

Solution

http://jqueryui.com/demos/autocomplete/#remote

    $( "#birds" ).autocomplete({
        source: "search.php",
        minLength: 2,
        select: function( event, ui ) {
            log( ui.item ?
                "Selected: " + ui.item.value + " aka " + ui.item.id :
                "Nothing selected, input was " + this.value );
        }
    });

The php needs to return values in Json format like this http://jqueryui.com/resources/demos/autocomplete/search.php?term=ai

Json instructions http://us2.php.net/json

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top