Last active
November 11, 2017 05:02
-
-
Save DeoThemes/49f63cb29f9a9ddff0adccbb3ca57ba6 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/xevukep
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="posts"></div> | |
<script id="jsbin-javascript"> | |
var request = new XMLHttpRequest(); | |
var method = "GET"; | |
var url = "https://jsonplaceholder.typicode.com/users"; | |
var postsContainer = document.querySelector("#posts"); | |
request.open(method, url); | |
request.onreadystatechange = function() { | |
if (request.readyState === XMLHttpRequest.DONE && request.status === 200) { | |
var data = JSON.parse(request.responseText); | |
printOutput(data); | |
} else if (request.readyState === XMLHttpRequest.DONE && request.status !== 200) { | |
console.log("Request failed!"); | |
} | |
} | |
request.send(); | |
function printOutput(data) { | |
var htmlString = ""; | |
htmlString += "<ul>"; | |
for (var i = 0; i < data.length; i++) { | |
htmlString += "<li>" + data[i].name + "</li>"; | |
} | |
htmlString += "</ul>"; | |
postsContainer.innerHTML = htmlString; | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var request = new XMLHttpRequest(); | |
var method = "GET"; | |
var url = "https://jsonplaceholder.typicode.com/users"; | |
var postsContainer = document.querySelector("#posts"); | |
request.open(method, url); | |
request.onreadystatechange = function() { | |
if (request.readyState === XMLHttpRequest.DONE && request.status === 200) { | |
var data = JSON.parse(request.responseText); | |
printOutput(data); | |
} else if (request.readyState === XMLHttpRequest.DONE && request.status !== 200) { | |
console.log("Request failed!"); | |
} | |
} | |
request.send(); | |
function printOutput(data) { | |
var htmlString = ""; | |
htmlString += "<ul>"; | |
for (var i = 0; i < data.length; i++) { | |
htmlString += "<li>" + data[i].name + "</li>"; | |
} | |
htmlString += "</ul>"; | |
postsContainer.innerHTML = htmlString; | |
}</script></body> | |
</html> |
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
var request = new XMLHttpRequest(); | |
var method = "GET"; | |
var url = "https://jsonplaceholder.typicode.com/users"; | |
var postsContainer = document.querySelector("#posts"); | |
request.open(method, url); | |
request.onreadystatechange = function() { | |
if (request.readyState === XMLHttpRequest.DONE && request.status === 200) { | |
var data = JSON.parse(request.responseText); | |
printOutput(data); | |
} else if (request.readyState === XMLHttpRequest.DONE && request.status !== 200) { | |
console.log("Request failed!"); | |
} | |
} | |
request.send(); | |
function printOutput(data) { | |
var htmlString = ""; | |
htmlString += "<ul>"; | |
for (var i = 0; i < data.length; i++) { | |
htmlString += "<li>" + data[i].name + "</li>"; | |
} | |
htmlString += "</ul>"; | |
postsContainer.innerHTML = htmlString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment