Created
January 25, 2011 18:39
-
-
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
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
<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(" "); | |
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