xmlhttp.open, does not accept subfolders

Asked

Viewed 32 times

0

I have a problem. I do the Xmlhttp request and everything works fine, however, when opening the json it does not load, because it is inside a folder, I try as follows ("GET", "data/data.json", true), but does not open. If I use the file outside the folder it works"GET", "data.json", true).

I wonder if there is any way to load the file in the folder?

window.onload = function(){
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){
        if(this.readyState === 4 && this.status === 200){
            var poke = JSON.parse(this.responseText);
            Element.prototype.appendAfter = function (element) {
                element.parentNode.insertBefore(this, element.nextSibling);
            }, false;
            var NewElement = document.createElement('tr');
            NewElement.innerHTML = '<td>'+poke[i].id+'</td><td>'+poke[i].name+'</td><td><img src="'+poke[i].picture+'"/></td>';
            NewElement.appendAfter(document.getElementsByClassName('head-table'));
            NewElement.innerHTML = '<td>ID</td><td>Name</td><td>Picture</td>';
            NewElement.appendAfter(document.getElementById('ref'));
            for(i=0;i<poke.length;i++){
                var NewElement = document.createElement('tr');
                NewElement.innerHTML = '<td>'+poke[i].id+'</td><td>'+poke[i].name+'</td><td><img src="'+poke[i].picture+'"/></td>';
                NewElement.appendAfter(document.getElementById('ref'));
            }
        }
    };
    xmlhttp.open("GET", "data/dados.json", true);
    xmlhttp.send();
};

  • What appears on the console? There must be an error. That must be the problem https://answall.com/q/2315/3635 (relative paths)

  • Address of the page making the request ?

  • I managed, for some reason I was not going before, then today when I sat on my computer and decided to try again without any modifications was. But thank you all!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.