JSFiddle - React, Tailwind, and code Playground
HTML
<h1>Dynamically loaded list Sample</h1>
Country:<input type="text" name='country' id='country'>
<input type="button" value="show" id="name-submit">
<div id="name-data"></div>
JavaScript
function loadlist(selobj,url,nameattr)
{
var adata =[]; //define empty array
$.getJSON(url,{crossDomain: true},function(data)
{
adata = []; //on callback empty array
$.each(data, function(i,obj)
{
if (obj[nameattr] !== '')
{
adata.push(obj[nameattr]); //push element into array
}
});
$( "#country" ).autocomplete({
source: adata //init autocomplete with newly formed array
});
});
}
$(function()
{
loadlist($('#country').get(0), 'http://funiks.com/invoice/phonebook/dropdown-ajax/get-list.php?getlist=contactname','contactname');
});
$('input#name-submit').on('click',function(){
var name = $('input#country').val();
if($.trim(name) !=''){
$.post('http://funiks.com/invoice/phonebook/search/returnresult.php',{name : name}, function(data){
alert(name);
$('div#name-data').text(data);
});
}
});
// my php code- http://pastebin.com/WxbV5Ns4 , the above last line is not //working, i am not getting the data from my php file