Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Remote JSONP datasource</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
</head>
<body>

Operating Systems



<label for="select">Choose: </label>
<input type="text" id="select" />
<script>
(function () {
var url = "http://localhost:61397/CompanyRestService.svc/GetCompID/0";
var items = [];
$.getJSON(url)
.done(function (data) {
$.each(data, function (i, item) {
items[i] = item.CompanyLegalName;
});
});
$('#select').autocomplete({
source: items
});
})();
</script>
</body>
</html>
HTML



What I have tried:

my Rest service output:

[{"Id":155,"Name":"DOMEX E-DATA PRIVATE"},{"Id":156,"Name":"HCL COAL INTERNATIONAL PRIVATE LIMITED"},{"Id":158,"Name":"Roja Builders and services"},{"Id":159,"Name":"TATA ADVANCED MATERIALS LIMITED"},{"Id":161,"Name":" Tikona BroadBand ltd"},{"Id":166,"Name":"DOMEX TECHNICAL INFORMATION PRIVATE LIMITED"},{"Id":168,"Name":"Philips India"},{"Id":170,"Name":"Docomo"},{"Id":171,"Name":"AIRTEL SOFTWARE SOLUTIONS PRIVATE LIMITED"},{"Id":172,"Name":"RELIANCE INDUSTRIES LIMITED"}
HTML

]



I m fresher for jquery...I dont know to show autocomplete on textbox with rest service...kindly help...
Posted
Updated 23-Jun-16 3:35am

you will have to add reference to Jquery UI[^]

add below two reference.
HTML
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
   <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>


for complete reference refer Jquery AutoComplete[^]
Autocomplete with Remote JSON[^]
 
Share this answer
 
v2
Comments
venkatesh (chennai) 23-Jun-16 9:41am    
Dear sir,

I m trying the above two link ..they perfectly work....but I change Url to My rest service the could not work... plz help...today fully i m work on autocomplete only...
Karthik_Mahalingam 23-Jun-16 9:43am    
okare you able to get result in
.done(function (data) {
venkatesh (chennai) 23-Jun-16 9:45am    
yes sir....i am able to see result on alert( item.Name);
Karthik_Mahalingam 23-Jun-16 9:48am    
Then problem with auto complete only
Add the jQuery ui js and css library and check
venkatesh (chennai) 23-Jun-16 9:53am    
ok sir
items[i] = item.CompanyLegalName; 


There is no "CompanyLegalName" property in you data, it is just called "Name".
 
Share this answer
 
Comments
venkatesh (chennai) 23-Jun-16 9:36am    
i will change ...but not work
items[i] = item.Name;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900