Last active
December 21, 2015 02:49
-
-
Save mbjorkegren/6237572 to your computer and use it in GitHub Desktop.
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
// 1. Create your own gist in another tab, and add a JSON object as the contents, like this | |
// { "name": "Mike" } | |
// 2. Save the gist, and click <> and copy the url, then hit your back button. | |
// 3. In Chrome dev tools, open the console (hit esc), and create a variable to store the url. | |
var url = "https://gist.github.com/mbjorkegren/6236844/raw/78e11f7afe3303f860bc35ef9d94316b66349d50/gistfile1.txt"; | |
// 3. Get the contents from the server, and log the result. | |
function log(x) { | |
console.log(x); | |
} | |
$.get(url).done(log) | |
// 5. Now let's try to use the data to add something to the DOM, using a simple template. | |
function render(data) { | |
$("#header").html("<div>" + data.name + "</div>"); | |
} | |
// Try changing the logo. | |
$.get(url).done(render) | |
// undefined??? | |
// Tell $.get that the response is JSON | |
$.get(url,null,null,"json").done(render) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment