开发者

JQuery Autocomplete with AJAX

开发者 https://www.devze.com 2023-01-29 05:44 出处:网络
I\'m trying to write a JQuery autocomplete sc开发者_StackOverflowript which will call a url via AJAX and update autocomplete results as user enters data into the form.

I'm trying to write a JQuery autocomplete sc开发者_StackOverflowript 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消