XHR(XML HTTP Request)
var btn = document.querySelector("button");
var display = document.querySelector("#price");
var currency = "USD";
btn.addEventListener("click", function(){
var XHR = new XMLHttpRequest(); fetch(url)
XHR.onreadystatechange = function(){ .then(function(response){
if(XHR.readyState == 4 && XHR.status == 200){ return response.json()
var data = JSON.parse(XHR.responseText); })
var price = data.bpi[currency].rate; .then(function(data){
display.innerText= price + " " = currency; console.log(data.bpi.EUR.rate);
} });
}
XHR.open("GET", "https://api.coindesk.com/v1/bpi/currentprice.json");
XHR.send();
})
'Udemy > Web Dev BootCamp' 카테고리의 다른 글
Advanced Array Methods(map) (0) | 2019.02.19 |
---|---|
Advanced Array Methods(forEach) (0) | 2019.02.19 |
4 Ways AJAX(xhr / fetch / jquery / axios) (0) | 2019.02.18 |
Fetch Random User Profile Generator 코드리뷰 (0) | 2019.02.17 |
Async Foundation (0) | 2019.02.13 |