The question is purely for educational purposes, this is not a problem.
When processing onreadystatechange 3 packages arrive (if I understand correctly, responseText - that is where the text of the packages is stored in a representative form).
The first one is empty ( why?, By the way).
The second one displays all the artworks.json .
The third displays the same thing as the second ( why? ).
Maybe it's in json? And yet such a thing as a controlling stake comes to mind (I don’t know how I know about this). Please clarify what is happening here)
Here is my function that performs ajax:
function artAjaxRequest(pageSrc) { var artworks; var xhr = new XMLHttpRequest(); xhr.open('GET', '/artworks/artworks.json', true); xhr.send(); xhr.onload = function(){ artworks = JSON.parse(this.responseText); }; xhr.onreadystatechange = function(){ alert(this.responseText); }; return function() { // Заглушка }; } Purely for reference artworks.json itself:
{ "sketches": [ { "title": "какой-то тайтл 1-го арта", "description": "какое-то описание 1-го", "date": "23.02.2017 19:42", "src": "1.png" }, { "title": "какой-то тайтл 2-го арта", "description": "какое-то описание 1-го арта", "date": "23.02.2017 19:43", "src": "2.png" }, { "title": "какой-то тайтл 3-го арта", "description": "какое-то описание 1-го арта", "date": "23.02.2017 19:43", "src": "3.png" } ], "somethingserious": [ { "title": "какой-то тайтл 3-го арта", "description": "какое-то описание 1-го арта", "date": "23.02.2017 19:44", "src": "1.png" }, { "title": "какой-то тайтл 3-го арта", "description": "какое-то описание 1-го арта", "date": "23.02.2017 19:44", "src": "2.png" }, { "title": "какой-то тайтл 3-го арта", "description": "какое-то описание 1-го арта", "date": "23.02.2017 19:41", "src": "3.png" } ] }