Skip to content

Instantly share code, notes, and snippets.

@ashlynstill
Created October 27, 2013 21:52
Show Gist options
  • Save ashlynstill/7188301 to your computer and use it in GitHub Desktop.
Save ashlynstill/7188301 to your computer and use it in GitHub Desktop.
importing json with ajax
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<head>
<title>Testing Ajax</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- script for loading/outputting your data -->
<script type="text/javascript">
//load your document
$(document).ready(function(){
console.log('document ready!'); //check and make sure jquery is loaded
//jquery using AJAX to pull in a JSON file located in data folder
$.getJSON( "data/pensions.json", function( data ) {
console.log(data); /// your data variable holds your json! look at the console.log to see if the json loaded in properly
//lets loop through our data, shall we?
for (var i=0;i<data.length;i++){
$('#json').append('<div id="json'+i+'"></div>'); //make a div for each object
$('#json'+i).append('<h3>'+data[i].pension_name+'</h3><ul id="list'+i+'"></ul>'); //put the name of the pension in a header in the div it's assigned to, and add a list for the specific index below it
$('#list'+i).append('<li>Surplus:'+data[i].surplus+'</li><li>Ratio:'+data[i]._2013+'</li>'); //prints content of each pension to a little list below its name
}
});
});
</script>
</head>
<body>
<div id="json">
<h1>My JSON Data</h1>
</div>
<div id="xml_div">
<h1>My XML Data</h1>
<ul id="xml_list">
</ul>
</div>
</body>
</html>
[
{
"pension_name": "Alpharetta Enhanced Defined Benefit Plan",
"surplus": "($2,887,155)",
"_2013": "118.42",
"_2011": "87.7",
"_2009": "n/a",
"_2007": "n/a"
},
{
"pension_name": "Alpharetta Retirement Plan",
"surplus": "$6,017,019",
"_2013": "67.24",
"_2011": "63.68",
"_2009": "n/a",
"_2007": "n/a"
},
{
"pension_name": "Atlanta Board of Education",
"surplus": "$554,417,183",
"_2013": "17.13",
"_2011": "17.42",
"_2009": "20.68",
"_2007": ""
},
{
"pension_name": "Atlanta Firefighter's Pension Plan",
"surplus": "$276,383,168",
"_2013": "60.47",
"_2011": "57.61",
"_2009": "64.21",
"_2007": "73.05"
},
{
"pension_name": "Atlanta General Employees' Pension Plan",
"surplus": "$747,361,057",
"_2013": "53.7",
"_2011": "59.46",
"_2009": "52.17",
"_2007": "59.56"
},
{
"pension_name": "Atlanta Housing Authority",
"surplus": "($1,007,240)",
"_2013": "102.65",
"_2011": "106.98*",
"_2009": "109.77",
"_2007": "102.28"
},
{
"pension_name": "Atlanta Police Officers' Pension Plan",
"surplus": "$398,619,427",
"_2013": "59.76",
"_2011": "57.97",
"_2009": "65.59",
"_2007": "67.46"
},
{
"pension_name": "Atlanta Regional Commission Retirement Plan",
"surplus": "$5,953,679",
"_2013": "81.41",
"_2011": "64.66",
"_2009": "91.95",
"_2007": "77.77"
},
{
"pension_name": "Avondale Estates Retirement Plan",
"surplus": "$403,940",
"_2013": "71.53",
"_2011": "75.05",
"_2009": "79.57",
"_2007": "84.03"
},
{
"pension_name": "Buford Retirement Plan",
"surplus": "$2,436,329",
"_2013": "68.33",
"_2011": "64.91",
"_2009": "97.31",
"_2007": "101.70"
},
{
"pension_name": "Chamblee Retirement Plan",
"surplus": "$233,418",
"_2013": "98.33",
"_2011": "94.35",
"_2009": "94.88",
"_2007": "100.83"
},
{
"pension_name": "Clayton County Public Employees Retirement Plan",
"surplus": "$117,767,407",
"_2013": "72.35",
"_2011": "71.73",
"_2009": "72.96",
"_2007": "78.45"
},
{
"pension_name": "Cobb County Board of Commissioners Retirement Income Plan",
"surplus": "$337,406,503",
"_2013": "53.99",
"_2011": "55.01",
"_2009": "60.08",
"_2007": "70.18"
},
{
"pension_name": "Cobb County-Marietta Water Authority",
"surplus": "$2,841,105",
"_2013": "88.07",
"_2011": "90.28",
"_2009": "94.77",
"_2007": "n/a"
},
{
"pension_name": "Decatur Employees Retirement System",
"surplus": "$8,506,151",
"_2013": "76.62",
"_2011": "78.51",
"_2009": "85.91",
"_2007": "n/a"
},
{
"pension_name": "DeKalb County Employees Retirement Plan (Pension Plan) *",
"surplus": "$608,832,769",
"_2013": "66.14",
"_2011": "72.1",
"_2009": "84.71",
"_2007": "99.04"
},
{
"pension_name": "Fayette County Pension Plan",
"surplus": "($612,466)",
"_2013": "103.4",
"_2011": "n/a",
"_2009": "n/a",
"_2007": "n/a"
},
{
"pension_name": "Fulton County Employees Pension Plan",
"surplus": "$499,684,000",
"_2013": "68.86",
"_2011": "INP",
"_2009": "86.26",
"_2007": "83.32"
},
{
"pension_name": "Fulton County Schools Employees' Pension Plan",
"surplus": "$223,905,000",
"_2013": "50.5",
"_2011": "48.75",
"_2009": "*",
"_2007": "*"
},
{
"pension_name": "Fulton-DeKalb Hospital Authority",
"surplus": "$53,786,556",
"_2013": "78.39",
"_2011": "INP",
"_2009": "*",
"_2007": "*"
},
{
"pension_name": "Gwinnett County Board of Education Retirement System",
"surplus": "$24,886,146",
"_2013": "98.05",
"_2011": "103.43",
"_2009": "102.54",
"_2007": "102.32"
},
{
"pension_name": "Gwinnett County Public Employees Retirement System (Pension Plan)",
"surplus": "$196,739,503",
"_2013": "76.83",
"_2011": "70.16",
"_2009": "79.2",
"_2007": "76.18"
},
{
"pension_name": "Henry County Pension Plan",
"surplus": "$42,019,810",
"_2013": "63.14",
"_2011": "64.24",
"_2009": "61.72",
"_2007": "49.03"
},
{
"pension_name": "Henry County Water and Sewerage Authority",
"surplus": "$7,873,462",
"_2013": "67.51",
"_2011": "59.52",
"_2009": "43.65",
"_2007": "24.27"
},
{
"pension_name": "Kennesaw Retirement Plan",
"surplus": "$2,211,992",
"_2013": "79.52",
"_2011": "79.97",
"_2009": "79.42",
"_2007": "71.85"
},
{
"pension_name": "Lithonia Retirement Plan",
"surplus": "($272,373)",
"_2013": "173.19",
"_2011": "209.47",
"_2009": "155.19",
"_2007": "155.52"
},
{
"pension_name": "Marietta Pension Plan",
"surplus": "$66,210,448",
"_2013": "55.15",
"_2011": "53.06",
"_2009": "57.67",
"_2007": "67.05"
},
{
"pension_name": "MARTA Non-Represented Pension Plan",
"surplus": "$164,609,183",
"_2013": "61.84",
"_2011": "62.36",
"_2009": "68.54",
"_2007": "60.59"
},
{
"pension_name": "MARTA Union Employees Retirement Plan",
"surplus": "$7,251,445",
"_2013": "98.45",
"_2011": "99.36",
"_2009": "111.17",
"_2007": "101.46"
},
{
"pension_name": "Norcross Retirement Plan",
"surplus": "$1,766,738",
"_2013": "79.29",
"_2011": "78.46",
"_2009": "86.43",
"_2007": "83.46"
},
{
"pension_name": "Peachtree City Retirement Plan",
"surplus": "$5,453,905",
"_2013": "77.79",
"_2011": "76.22",
"_2009": "78.36",
"_2007": "83.95"
},
{
"pension_name": "Smyrna Retirement Plan",
"surplus": "$10,532,330",
"_2013": "77.7",
"_2011": "76.61",
"_2009": "83.32",
"_2007": "79.43"
},
{
"pension_name": "Stone Mountain Retirement Plan",
"surplus": "($37,098)",
"_2013": "101.59",
"_2011": "104.24",
"_2009": "100.33",
"_2007": "108.27"
},
{
"pension_name": "Suwanee Retirement Plan",
"surplus": "($1,488,040)",
"_2013": "162.14",
"_2011": "167.69",
"_2009": "129.76",
"_2007": "n/a"
},
{
"pension_name": "TOTALS",
"surplus": "$4,367,805,301",
"_2013": "",
"_2011": "",
"_2009": "",
"_2007": ""
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment