Skip to content

Instantly share code, notes, and snippets.

@davidwhitney
Created January 25, 2011 18:39
Show Gist options
  • Save davidwhitney/795369 to your computer and use it in GitHub Desktop.
Save davidwhitney/795369 to your computer and use it in GitHub Desktop.
Example of using the JustGiving API to do a quick and dirty charity search
<html>
<head>
<title>My Kickass JustGiving search</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<body>
JustGiving AJAX Search Quick Example
<br/><br/>
<script type="text/javascript">
/ * Excuse my inline jQuery, for example purposes only! */
function DoSearch()
{
var searchTerm = $('#searchText').val();
var url = "https://api.staging.justgiving.com/9a9c05b1/v1/charity/search?q=" + encodeURIComponent(searchTerm) + "&format=json&callback=?";
$('#hint').text("Calling: " + url);
jQuery.getJSON(url, function(data) {
$('#results').html("&nbsp;");
jQuery.each(data.charitySearchResults, function(index) {
var dataItem = data.charitySearchResults[index]
var newItem = "Charity Id: " + dataItem.charityId + "<br/>";
newItem += "Name: " + dataItem.name + "<br/>";
newItem += "Description: " + dataItem.description + "<br/>";
$('#results').html($('#results').html() + "<hr/>" + newItem);
});
});
}
</script>
<div id="hint"></div>
<input type="textbox" id="searchText" />
<input type="button" value="Search" id="searchButton" onclick="DoSearch()"/>
<div id="results"></div>
</body>
<html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment