Try this .I have pasted both page code and class code there.Paste those code in proper place it will work fine.
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css"></link>
.ui-autocomplete-loading {
background:url('/img/loading32.gif') right center no-repeat !important;
background-size:15px 15px !important;
margin-right:5px;
}
$(document).ready(function(){
var allAcc;
$("[id$='txtCompanyName']").autocomplete(
{
minLength: 3,
source: function(request, response){
queryTerm = request.term;
UserController.initializeAcc(request.term, function(result, event)
{
if(event.type == 'exception')
{
alert(event.message);
}
else
{
allAcc = result;
response(allAcc);
}
});
},
focus: function( event, ui ){
$("[id$='txtCompanyName']").val( ui.item.Name );
return false;
},
select: function( event, ui ) {
$("[id$='txtCompanyName']").val( ui.item.Name );
return false;
}
})
.autocomplete( "instance" )._renderItem = function( ul, item )
{
return $( "
" )
.append( "" + item.Name +"
" + item.BillingCity+','+item.BillingStreet+','+item.BillingState+','+item.BillingPostalCode+','+item.BillingCountry + "" )
.appendTo( ul );
};
});
========================Class Code==============================
@RemoteAction
public static list initializeAcc(String searchString)
{
list accList = new list();
String accName = searchString.trim();
if(accName !='')
{
String queryString = 'select Id,Name, BillingCity,BillingStreet,BillingState,BillingPostalCode,BillingCountry from Account where Name like \'' +accName+ '%\'';
try
{
accList = Database.query(queryString);
}
catch(QueryException e)
{
System.debug('======Exception getting specif Account'+e);
}
}
return accList;
}