Как вставить JSON в web
'use strict';
let inpRub = document.getElementById('rub'),
inpUsd = document.getElementById('usd');
console.log(inpRub);
console.log(inpUsd);
inpRub.addEventListener('input', () => {
let request = new XMLHttpRequest();
request.open('GET', '/json.json');
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
request.send();
request.addEventListener('load', function() {
if (request.readyState === 4 && request.status == 200) {
let data = JSON.parse(request.response);
inpUsd.Value = inpRub.Value / data.usd;
} else {
inpUsd.Value = 'sorry';
}
});
});
<!DOCTYPE html>
<html lang="ru">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link rel="stylesheet" href="2css.css">
<title>AJAX</title>
</head>
<body>
<h1 id="textrub" class="textinp">RUB
<input id="rub" type="text"></h1>
<h1 id="textusd" class="textinp">USD
<input id="usd" type="text"></h1>
<script src="2js.js"></script>
</body>
</html>
{
"usd": 75
}
Хочу сделать конвертер валюты для практики. Когда запускаю все это на лайв сервере, не вижу .json файла на странице и соответственно ничего не работает. Просьба указать мне на мои ошибки и показать как правильно нужно делать.