php - load data from database instead of array -
i using jquery plugin tag-it autocomplete tags in form input field. plugin loads available tags stored in array.
$("#mytags").tagit({ availabletags: ["c++", "java", "php", "javascript", "ruby", "python", "c"] });
i copied following function plugin's javascript code, believe main function load tags:
tag_input.autocomplete({ source: options.availabletags, select: function(event,ui){ if (is_new (ui.item.value)) { create_choice (ui.item.value); } // cleaning input. tag_input.val(""); // preventing tag input update chosen value. return false; } });
the plugin works fine , autocomplete tags availabletags array, make small change in it. instead of loading tags array, load tags mysql database table. table has following structure:
tags:
tag_id tag_name 1 c++ 2 java 3 php 4 javascript 5 ruby
so how can autoload tag names database (using php) instead of loading above array? thanks.
yes can like:
instead of
source: options.availabletags
use this:
source: function(request, response) { var term = request.term // hold text typed in autocomplete $.get(url, data, function(data){ // build array return var datatoreturn = []; }); response(datatoreturn); }
Comments
Post a Comment