Skip to content

Instantly share code, notes, and snippets.

@s2t2
Created February 8, 2018 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s2t2/0540ae3ebc8a3d98f60b1434a5b41767 to your computer and use it in GitHub Desktop.
Save s2t2/0540ae3ebc8a3d98f60b1434a5b41767 to your computer and use it in GitHub Desktop.
search usa gov jquery
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button type="button" name="button" id="search-button">Search</button>
<ul id="my-list"></ul>
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/javascript">
$("#search-button").click(search);
function search(){
var searchTerm = "ato" //todo: get this from an input instead of hard-coding
var url = 'https://search.usa.gov/api/v2/search?affiliate=fedramp&access_key=pkwSg7Bh0i05jHA-ubLZkuVx5gz_AIL0HVPc09Vq_VQ=&query=' + searchTerm;
$.getJSON(url, function(json) {
//console.log("GOT SOME DATA:", json.web.results)
json.web.results.forEach(function(result){
console.log(result)
$('#my-list').append("<li><a href='" + result.url + "'>" + result.title + "</a></li>")
});
});
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment