Using this commadelimited autocomplete I have created a php file to get some values from my MySQL database the created php script is follows
<?php
$connection = mysql_connect("my_host", "usr", "pwd"); // Establishing connection with server..
$db = mysql_select_db("appdb", $connection); 
$wid =$_POST['wid1'];
$result = mysql_query("select * from shop where wid=$wid");
$to_encode = array();
$data = mysql_num_rows($result);
if ($data > 0){
    while($row = mysql_fetch_assoc($result)) {
  $to_encode[] = $row;
}
echo json_encode($to_encode);
}
else{
    echo "No Shops Available, Contact Your Wholesaler !!";
}
mysql_close ($connection); // Connection Closed.
?>
and I have created a function in JavaScript to fetch values into a variable
$.post("http://theurl.com/app/get_shopname.php",{ wid1:10},
function(shopnames){
if(shopnames=='No Shops Available, Contact Your Wholesaler !!'){
$('input[type="text"],input[type="searchField"]').css({"border":"2px solid red","box-shadow":"0 0 3px red"});
alert(shopnames);
}else{
var availableTags = shopnames;
}
    }
    );
$("#searchField").autocomplete({
    target: $('#suggestions'),
    source: availableTags,
    link: 'target.html?term=',
    minLength: 1
});
The problem is, it doesn't enters inside  function(shopnames) function when hit $.post("http://theurl.com/app/get_shopname.php" .. it simply passing to the next function
 
     
    