Created
April 20, 2016 10:39
-
-
Save auchomage/1f008976d231240640c88a4332d78231 to your computer and use it in GitHub Desktop.
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
/* This file simulates how to access a native json file*/ | |
var output = document.getElementById('output'); | |
var ajaxhttp = new XMLHttpRequest(); // creates a js object with required functiionality | |
var url = "json.json"; // the exteranal json file | |
ajaxhttp.open("GET", url, true); // access the json file | |
ajaxhttp.setRequestHeader("content-type", "application/json"); // value sent over to the server, indicating | |
// what type of content the browser expects to receive | |
/* | |
readyState - represents communication with an external file | |
status - a flag used to indicate the success or failure of communication | |
*/ | |
ajaxhttp.onreadystatechange = function(){ | |
if(ajaxhttp.readyState == 4 && ajaxhttp.status == 200){ | |
var jcontent = ajaxhttp.responseText; | |
console.log( jcontent); // displays the response text | |
console.log("ajaxhttp = ", ajaxhttp); // displays the object | |
} | |
}; | |
ajaxhttp.send(null); // currently sending nothing back | |
output.innerHTML ="nothing"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment