Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Promices Demo</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link href="css/style.css" rel="stylesheet">
- <script>
- var url = "https://api.privatbank.ua/p24api/pubinfo?exchange&json&coursid=11";
- function CallCORS() {
- var XHR = window.XDomainRequest || window.XMLHttpRequest
- var xhr = new XHR();
- xhr.open('GET', url, true); // замена onreadystatechange
- xhr.onload = function() {
- let str = "<table>";
- let data = JSON.parse(xhr.responseText);
- for (let item of data) {
- str += `<tr><td>${item.ccy}</td><td>${item.base_ccy}</td><td>${item.buy}</td><td>${item.sale}</td></tr>`;
- }
- document.getElementById("ajax-results").innerHTML = str + "</table>";
- }
- xhr.onerror = function() {
- alert("Error")
- }
- xhr.send()
- }
- function init() {
- try {
- CallCORS()
- } catch (e) {
- alert("В этом браузере данная фича не поддерживается.")
- }
- // function init() {
- // $.ajax({
- // crossDomain: true,
- // url: "https://api.privatbank.ua/p24api/pubinfo?exchange&json&coursid=11",
- // type: "GET",
- // success: function(data) {
- // //called when successful
- // let str = "<table>";
- // for (let item of data) {
- // str += `<tr><td>${item.ccy}</td><td>${item.base_ccy}</td><td>${item.buy}</td><td>${item.sale}</td></tr>`;
- // }
- // $("#ajax-results").html(str + "</table>");
- // },
- // error: function(e) {
- // //called when there is an error
- // console.log(e.message);
- // }
- // });
- // }
- }
- </script>
- </head>
- <body onload="init()">
- <table id="ajax-results">
- </table>
- <script src="node_modules/jquery/dist/jquery.js"></script>
- <!--<script src="demo.js"></script>-->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement