I am trying to run the following script:
<button id="loadNoTextFile">Try</button>
<div id="textNoData"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#loadNoTextFile").click(function (e) {
$("#textNoData").load("no-file.txt", function (response, status, xhr) {
if (status == "error")
$("#textNoData").html("Error: " + xhr.status + ": " + xhr.statusText);
});
});
});
</script>
However, instead of the supposed Error 404, I get Error 0 (this is a sample code from thise website: https://www.yogihosting.com/jquery-load/ )
I have also tried to load a file that does exist on my computer (right next to this html file), but it will not load it. Can somebody please help me solve this?
edit: Opening web console, I got the following error message in the Debugger tab: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///D:/Games/WORK/Agrisol/website/no-file.txt. (Reason: CORS request not http).
edit2: For further clarification, my end goal is to load html code into my website when a button is clicked. This website will be hosted on a VPS, not on my personal computer.