How to read file from resources in laravel 9

Viewed 55

I have these code

function loadXMLDoc() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("app").innerHTML =
                this.responseText;
        }
    };
    xhttp.open("GET", "../resources/views/livewire/overview.blade.php", true);
    xhttp.send();
}
setInterval(function () {
    loadXMLDoc();
}, 1000);

window.onload = loadXMLDoc;

I'm trying to read overview.blade.php here xhttp.open("GET", "../resources/views/livewire/overview.blade.php", true); but I keep getting 404 not found, so my question is how to read a file outside the public folder.

1 Answers

You cannot! And you shouldn't do that!

From client (browser) perspective your "root url" is the /public folder.

possible solution

create a controller that returns this view you want to access, create a route to this controller and access that in your js file.

Related