javascript - How to pass selected value as extra parameter to ajax call -


my coding part

$("#demo-input").tokeninput("data/autosuggest-search-city.php",          {             searchdelay: 2000,             minchars: 3,             tokenlimit: 10         }); 

i want send selected values parameter "data/autosuggest-search-city.php".

for example, search , select 1 value list again searching, time want send 1st selected value server.

how this?

tokeninput plugin doesn't support natively.
can make simple workaround update "ajax url" whenever token added or removed selection.

use onadd , ondelete callbacks trigger "ajax url" changes;
selected tokens using selector.tokeninput("get") method;
set new "ajax url" updating .data("settings").url of element;

// cache original url: var token_url = "data/autosuggest-search-city.php";  $("#demo-input").tokeninput(token_url, {     searchdelay : 2000,     minchars    : 3,     tokenlimit  : 10,     onadd       : function(){         urlchange.call(this);     },     ondelete    : function(){         urlchange.call(this);     } });  function urlchange(){     var tokens = '', token_list = $(this).tokeninput("get");     // proceed if token/s selected:     if(token_list.length){         // loop through selected tokens (if more 1 selected)         $.each(token_list, function(i, token){             // use token "id" (or "name" if wish) , separate them comma:             tokens += token.id + ',';         });         // update url:         $(this).data("settings").url = token_url + '?selected_tokens='+tokens.replace(/,+$/,'');     }else{         // leave original url if no tokens selected:         $(this).data("settings").url = token_url;     } }; 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -