mercredi 9 novembre 2011

jQuery UI Autocomplete Widget with a POST request

The jQuery UI autocomplete plugin missed a 'method':'post' options to work with the remote page 'source' option. Hopefully, there is a trick to go threw :
$('#searchInput').autocomplete({
 source: function(request, response) {
  $.post( "/dosomething", { searchInput: request.term }, function( data ) {
   response(data)
  }
  , 'json'); 
 },
 minLength: 2,
 cache: false,
 select: function( event, ui ) {
  window.location.href = 'a_page';
 }
});
The trick is to provide a function as the source option. This function will perform to Post request to server a get a JSON response : [{'id':'1', 'label':'label1', 'value':'value1'}, {...}, ...].

1 commentaires:

  1. more over here - http://stackoverflow.com/questions/1512607/how-do-i-set-jquery-autocomplete-to-post-instead-of-get

    RépondreSupprimer