Created
February 8, 2018 15:45
-
-
Save s2t2/0540ae3ebc8a3d98f60b1434a5b41767 to your computer and use it in GitHub Desktop.
search usa gov jquery
This file contains 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> | |
<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