Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery TagIt (autocomplete) Fetching JSON list via AJAX

This is a question based on: Trying to get tag-it to work with an AJAX call

However the above just creates an error message of 'this.source is not a function' for me.

I am trying to get this json list to appear as the tag source for tagit via ajax. Code below:

// Tagit
$("#tags").tagit({      
    tagSource: function() {
        $.ajax({
            url: "/admin/ajax.php?q=fetch_all_tags",
            dataType: "json",
            success: function(data) {
                console.log(data);
                return data;
            }
        });
    }       
});

The ajax call returns:

{"4":"php","2":"html","3":"css"}
like image 805
Friendly Code Avatar asked Jun 19 '12 12:06

Friendly Code


2 Answers

Check out this code may help you

$("#mytags").tagit({
    autocomplete: {
        source: function( request, response ) {
            /*call api*/
        }
    }
});
like image 132
rjdmello Avatar answered Sep 23 '22 16:09

rjdmello


The autocomplete.source should be overridden if you want to use custom autocompletion sources, like an Ajax / XHR response.

For example:

$("#myTags").tagit({
    autocomplete: {
       delay: 0,
       minLength: 2,
       source : 'your data response'
    }
});
like image 30
cesar andavisa Avatar answered Sep 23 '22 16:09

cesar andavisa