2

I have a simple wikipedia autocomplete using the wikipedia's API.

Currently it is working using the jQuery autocomplete Plugin and I want to make it using jQuery UI.

Can someone guide me through please?

Here is the fiddle of a working demo using the plugin: http://jsfiddle.net/VjLnv/

And here is the JS:

function attachWikiAutoComplete(expression) {
    $("#artist").autocomplete("http://en.wikipedia.org/w/api.php",  {
        dataType: "jsonp", 
        parse: function(data) { 
            var rows = new Array(); 
            var matches = data[1];
            for( var i = 0; i < matches.length; i++){ 
                rows[i] = { data:matches[i], value:matches[i], result:matches[i] }; 
            } 
            return rows;
        },
        formatItem: function(row) { return row; }, 
        extraParams: {
            action: "opensearch", 
            format: "json", 
            search: function () { return $("#artist").val() } }, 
        max: 10 
    });
}

Thanks alot

1
  • I am using jQuery autocomplete Plugin instead of the default autocomplete which comes with jQuery ui and I want to change this so I won't be using that plugin. If you check the fiddle, try to remove the jquery.autocomplete.pack.js. It won't work anymore Commented Oct 20, 2011 at 11:07

1 Answer 1

8

This is the equivalent code in jQueryUI autocomplete:

$("#artist").autocomplete({
    source: function(request, response) {
        $.ajax({
            url: "http://en.wikipedia.org/w/api.php",
            dataType: "jsonp",
            data: {
                'action': "opensearch",
                'format': "json",
                'search': request.term
            },
            success: function(data) {
                response(data[1]);
            }
        });
    }
});

Working Example: http://jsfiddle.net/UGYzW/2/

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

1 Comment

Ey man literally I was wishing you would join my question. Haha, you done it again. You're inspiring me. What you know, its what I what I'm trying to learn

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.