Created
September 16, 2015 14:50
-
-
Save namaggarwal/cde54cd94061f92414ee to your computer and use it in GitHub Desktop.
JQuery AutoComplete Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
attachAutoComplete(); | |
}); | |
function attachAutoComplete(){ | |
$("#autocomp").autocomplete({ | |
source:function(req,res){ | |
$.ajax({ | |
url:"/auto", | |
data:{ | |
q:req.term | |
}, | |
success:function(data){ | |
data = $.parseJSON(data) | |
var retdata = [] | |
for(var i in data){ | |
retdata.push({label:data[i]["name"]+" "+data[i]["branch"],id:data[i]["id"]}) | |
} | |
res(retdata) | |
} | |
}) | |
}, | |
select:function(event,ui){ | |
//Write here what should happen on select | |
console.log(ui.item.id) | |
} | |
}) | |
} | |
function extractTerm(data){ | |
console.log(data) | |
return "Naman" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment