Load json data to autocomplete jquery

I am trying to use the jqueryui autocomplete to load services from mysql database on my form but nothing happens?? please help me or tell me where am wrong my htmlmy javascript script$(“#actual_service”).autocomplete(source: “http://dev_svr/medportal/search.php?callback=?”,dataType: “jsonp”, minLength: 1);this is search.php$con = mysql_connect(‘localhost’, ‘dev’, ”);…

via PHP Website Development » Search Results » ajax:

Load json data to autocomplete jquery

I am trying to use the jqueryui autocomplete to load services from mysql database on my form but nothing happens?? please help me or tell me where am wrong my html
my javascript script
$(“#actual_service”).autocomplete(
source: “http://dev_svr/medportal/search.php?callback=?”,
dataType: “jsonp”,
minLength: 1
);this is search.php
$con = mysql_connect(‘localhost’, ‘dev’, ”);
if (!$con)

die(‘Could not connect: ‘ . mysql_error());

mysql_select_db(“medrep”, $con);

$term = trim(strip_tags($_GET[‘term’]));

$qstring = “select prod_id id,prod_name value FROM product where prod_type=’SERVICE’ and prod_name LIKE ‘%”.$term.”%’ ORDER BY prod_name;”;
$result = mysql_query($qstring);
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))

$row[‘value’]=htmlentities(stripslashes($row[‘value’]));
$row[‘id’]=(int)$row[‘id’];
$row_set[] = $row;

header(“Content-type: application/json”);
echo json_encode($row_set);when i load that page nothing happens on that inputbox when i type anything.
this is a sample output of http://dev_svr/medportal/search.php?term=ct when i limit the sql to 3 rows
[“id”:50,”value”:”ABDOMEN SUPINE&ERECT(2VIEWS)”,”id”:142,”value”:”CT BRAIN”,”id”:115,”value”:”CT CERVICAL SPINE”]
…………………………………..

1. Your jQuery code is not correct
You are not getting data from a remote domain, therefore you don’t need a JSONP request. It should be:
$(“#actual_service”).autocomplete(
source: “http://dev_svr/medportal/search.php”,
minLength: 1
);2. Your JSON object is not correct.
Each json object for the autocomplete should have two values: label and value (no ID). If you want the product id to be the value of the selected item, and the product name to be the text that is shown to the user, then the json object should be like:
[“value”:50,”label”:”ABDOMEN SUPINE&ERECT(2VIEWS)”,”value”:142,”label”:”CT BRAIN”,”value”:115,”label”:”CT CERVICAL SPINE”]

Edit
From what you mentioned in the comments, try this jQuery code:
$(‘#actual_service’).autocomplete(
source: function( request, response )
$.ajax(
url: ‘http://dev_svr/medportal/search.php’,
dataType: ‘jsonp’,
data: term: request.term ,
success: function( data )
response( data );

});
},
minLength: 1
});

For more info: Load json data to autocomplete jquery

PHP Website Development » Search Results » ajax

Load json data to autocomplete jquery

Share this post:

Related Posts

Leave a Comment