Вот такой код вызывает у меня ошибку 404.
let dollar = document.querySelector('#DOLLAR'),
griv = document.querySelector('#GRIV');
dollar.addEventListener('input', function(e){
let server = new XMLHttpRequest();
server.open("GET", 'ajax/current.json');
server.setRequestHeader('Content-type','application/json; charset=utf-8');
server.send();
server.addEventListener('readystatechange', function(){
console.log(server)
console.log(server.status)
})
})
Не могу понять в чем ошибка пути правильные в json файле вот-такие данные:
{"usd": 27}
Ожидал что при вызове server.response вернется json объект который я потом преобразовал бы в обычный объект с помощью строки JSON.parse(server.response) , а вернулась вот такая белиберда :
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Object not found!</title> <link rev="made" href="mailto:%5bno%20address%20given%5d" /> <style type="text/css"><!--/*--><![CDATA[/*><!--*/ body { color: #000000; background-color: #FFFFFF; } a:link { color: #0000CC; } p, address {margin-left: 3em;} span {font-size: smaller;} /*]]>*/--></style> </head> <body> <h1>Object not found!</h1> <p> The requested URL was not found on this server. The link on the <a href="http://ajax.loc/">referring page</a> seems to be wrong or outdated. Please inform the author of <a href="http://ajax.loc/">that page</a> about the error. </p> <p> If you think this is a server error, please contact the <a href="mailto:%5bno%20address%20given%5d">webmaster</a>. </p> <h2>Error 404</h2> <address> <a href="/">ajax.loc</a><br /> <span>Apache</span> </address> </body> </html> script.js:15:5
404 script.js:16:5
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Object not found!</title> <link rev="made" href="mailto:%5bno%20address%20given%5d" /> <style type="text/css"><!--/*--><![CDATA[/*><!--*/ body { color: #000000; background-color: #FFFFFF; } a:link { color: #0000CC; } p, address {margin-left: 3em;} span {font-size: smaller;} /*]]>*/--></style> </head> <body> <h1>Object not found!</h1> <p> The requested URL was not found on this server. The link on the <a href="http://ajax.loc/">referring page</a> seems to be wrong or outdated. Please inform the author of <a href="http://ajax.loc/">that page</a> about the error. </p> <p> If you think this is a server error, please contact the <a href="mailto:%5bno%20address%20given%5d">webmaster</a>. </p> <h2>Error 404</h2> <address> <a href="/">ajax.loc</a><br /> <span>Apache</span> </address> </body> </html>
Что я делаю не так?