Ошибкак 404 при попытке создать GET запрос в javascript

181
23 июня 2019, 07:30

Имеется три файла (взято из примера: https://openclassrooms.com/en/courses/3523261-use-javascript-in-your-web-projects/3759261-make-your-first-ajax-request)

ajax-example.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="css/styles-ajax.css">
    <title>Title</title>
</head>
<script>
    var myRequest = new XMLHttpRequest();
    myRequest.open('GET', 'surprise-ajax.html');
    myRequest.onreadystatechange = function () {
        if (myRequest.readyState === 4) {
            document.getElementById('ajax-content').innerHTML = myRequest.responseText;
        }
    };
    function sendTheAJAX() {
        myRequest.send();
        document.getElementById('reveal').style.display = 'none';
    }
</script>
<body>
<h1>Today's your special day!</h1>
<button id="reveal" onclick="sendTheAJAX()" class="button">Why's that?</button>
<div id="ajax-content">
</div>
</body>
</html>

surprise-ajax.html

<h1 id="birthday-greeting">It's your birthday!</h1>

Ну и style-ajax.css

body {
    font-family: Helvetica;
    text-align: center;
}
#birthday-greeting {
    font-size: 72px;
    color: red;
    text-transform: uppercase;
}

Страница выводится. Но при нажатии кнопки Why's that? получаю ошибку 404:

{"timestamp":"2018-12-18T17:29:06.593+0000","status":404,"error":"Not Found","message":"No message available","path":"/surprise-ajax.html"}

Файл surprise-ajax.html разместил во всех папках пректа, но ситуацию не меняет.

Как решить?

READ ALSO
Некорректное отображение datepicker

Некорректное отображение datepicker

Ситуация следующаяЕсть datepicker, который имеет 2 варианта выпадения: над формой и под ней

154
Как подключить bootstrap datapicker в React приложение?

Как подключить bootstrap datapicker в React приложение?

Накидал страничку приложения на Bootstrap, подключаю DatePicker сначала ругается, что не знает, что такое $Установил jQuery, импортировал

172