這是基於一個問題:Trying to get tag-it to work with an AJAX calljQuery的TAG-IT(自動完成)擷取JSON列表通過AJAX
但上述只是創建了一個錯誤信息「this.source不是一個函數」對我來說。
我想讓這個json列表顯示爲tagit的標記源,通過ajax。下面的代碼:
// Tagit
$("#tags").tagit({
tagSource: function() {
$.ajax({
url: "/admin/ajax.php?q=fetch_all_tags",
dataType: "json",
success: function(data) {
console.log(data);
return data;
}
});
}
});
Ajax調用返回:
{"4":"php","2":"html","3":"css"}
非常感謝,@rjdmello你的代碼段可以正常使用,並在這裏是最好的答案。 – DccBr
melhor resposta。 – cura