remote datasource in jquery autocomplete -


i have show searched text in jquery autocomplete list. have function adding search text in list have remote datasource. have url returning array.

working demo static array list fiddle

i have add same functionality remote data source. how can add search text in response.

$(document).ready(function() {     var tagselem = $("#tags");     tagselem.autocomplete({         source : "search.php",         search : function( event, ui ){             if(check(response,tagselem.val()))               response[response.length]=tagselem.val()                           tagselem.autocomplete( "option", "source", response);         },         open: function( event, ui ) {             if(check(response,tagselem.val())){             tagselem.next().find('li:last a').append(' <span style="color:red;">new</span>');             }                    }     });      function check(arraytag,value){      for(i=0;i<len;i++){         if( arraytag[i]==value)                 return false         }         return true     }  }); 

i can see using jquery ui.

i assume know how change remote source , returns simple array answer.

as jquery ui works, changes simple json array to:

[{label:<array_value1>,value:<array_value1>},{label:<array_value2>,value:<array_value2>}] 

to accomplish want, have in response event do:

            response: function(index,obj){                 var v = tagselem.val();                 var add = {};                 add['label'] = v;                 add['value'] = v;                 obj.content[obj.content.length] = add;             } 

the 'obj.content' above json array.

that add search key response array.

please note 'tagselem' in above example refers tagselem in jsfiddle.

here example got working, not in fiddle on localhost: jsfiddle


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -