A
A
Andrey Iginov2020-04-26 13:13:18
AJAX
Andrey Iginov, 2020-04-26 13:13:18

Why is ajax not working?

Hello! I am writing code on a local server (Open Server) following the example from the video. But for some reason it doesn't work.
Here is the HTML:

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AJAX</title>
</head>
<body>
    <input type="button" id="shop_ip" value="Показать мой IP">
    <div id="myip"></div>
    <script src="script.js"></script>
</body>
</html>

Here is the JavaScript:
window.onload = function() {
    document.querySelector('#shop_ip').onclick = function() {
        ajaxGet();
    }
}

function ajaxGet() {
    var request = new XMLHttpRequest();
    request.open('GET', 'ip.php');
    request.send();
}

Here is PHP:
<?php
echo $_SERVER['REMOTE_ADDR'];

The person from the video has exactly the same code, and at the same time, after clicking on it, the following is displayed in the browser console.
5ea55c651ae96819440155.jpeg

For me, nothing is displayed.
5ea55ca9bbe6c373925973.jpeg

Here is how the files are located, if it is important:
5ea55d02ae607253286405.jpeg

I have some suspicions that this video is not new, so to speak, in browsers something has changed. That now it is displayed elsewhere, but these are just my thoughts, I want to know if this is true?
Here, "climbing" in the network tab in chrome, I saw the following.
5ea55de2891d2551892469.jpeg
5ea55deadeda7383143115.jpeg

Who knows, tell me please. What's the matter? I will be glad for any help. Thank you!

Oh, yes, that's what's on the page where the php code is. By this I want to show that php is working. Everything seems to be fine with him too.
5ea55e91341eb587115891.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question