Apologies for the basic question, but I'm feeling a bit lost at the moment.
I've been diving into learning JavaScript and decided to set up a page on the 00webhost site to experiment and run tests. Everything was going well until I hit a roadblock while following this tutorial on AJAX.
I tried uploading a text file to the server, experimenting with different paths like placing it in the same directory as the JavaScript file, providing full path, or even placing it at the public root. Unfortunately, every attempt resulted in a 404 server response.
Upon trying to access the file through my browser (Chrome), I received an error message stating "Failed to open." It seems like there's an issue with accessing the resource on the server, but I'm unsure about how to configure it correctly. Even changing the file permissions to 777 didn't help.
Considering this is a shared server on a free hosting service, could there be restrictions hindering my configuration?
In my index.html file, I utilize a button with the id "btnAjax" to later establish the event in the JavaScript file.
...
<div id="ajax">
<input type="button" id="btnAjax" value="Testing AJAX" onclick="getText('ajaxretrieve.txt')"/>
</div>
<script type="text/javascript" src="jsdir/ajax.js">
</script>
....
Regarding the JavaScript file (ajax.js), here's how the button links to the server response:
function getText(url)
{
if(window.XMLHttpRequest)
{
myRequest = new XMLHttpRequest();
}
else
{
myRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
myRequest.open("GET", url, true);
myRequest.send(null); // nothing to send
myRequest.onreadystatechange = getData;
}
// handles the server response
function getData()
{
var myBtn = document.getElementById("btnAjax");
if(myRequest.readyState === 4)
{
alert(myRequest.status);
if(myRequest.status === 200)
{
var text = myRequest.responseText;
myBtn.nodeValue = text;
}
}
}
Despite the code above, all I receive is an alert on the browser showing a status of 404. I have yet to achieve the successful status of 200.