Created
September 9, 2014 09:08
-
-
Save gpetz/55050eaac9f5e183acd4 to your computer and use it in GitHub Desktop.
pubmed autocomplete to jquery
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<!--http://hublog.hubmed.org/archives/001879.html--> | |
<title>Using PubMed's autocomplete data in JQuery</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
$("#search").submit(function() { | |
$.getJSON("http://preview.ncbi.nlm.nih.gov/portal/utils/autocomp.fcgi?dict=pm_related_queries_2&callback=?&q=" | |
+ encodeURIComponent($("#q").val()), NSuggest_CreateData); | |
return false; | |
}); | |
}); | |
function NSuggest_CreateData(q, data) { | |
var ul = $("#results"); | |
ul.empty(); | |
$.each(data, function(i, text) { | |
ul.append($("<li/>").text(text)); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<form id="search" action="search"> | |
<input name="q" id="q"> | |
<input type="submit" value="search"> | |
</form> | |
</body> | |
<ul id="results"></ul> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment