Для подробного ответа я пробовал с источником со случайными значениями.
<script type="text/javascript">
$(document).ready(function () {
var availableTags = [
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme",
"AngularJS",
"jQuery"
];
$("#clientName").autocomplete({
source: availableTags,
select: function( event, ui ) {
console.log(ui); // It has the value which we selected
var clientName = $('#clientName').val(); // It shows the value which we entered
if (clientName != '') {
$.ajax({
url: "php_action/fethClientByName.php",
method: "POST",
data: {
clientName: clientName
},
dataType: "JSON",
success: function (data) {
$('#client_details').css("display", "block");
$('#lblClientName').text(data.clientName);
$('#lblClientCompanyName').text(data.companyName);
}
})
} else {
$('#client_details').css("display", "none");
}
}
});
});
</script>