Unable to retrieve file from server

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.

Answer №1

For security purposes, .txt files are not allowed on 000webhost.

Reference:

You can try renaming the file extension to html or htm to see if that resolves the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When utilizing jade.compile for compiling a jade template containing mixins or included partials

I'm currently exploring solutions for this challenge. The issue at hand involves compiling a jade template for an email campaign, but the file I am attempting to compile is a mixin that includes some partials. Here's an example: controllers/us ...

Problem with Custom MUI fields not detecting value change

I want to make custom form components so I don't have to update each item individually if I want to change the style. The ReportSelect component doesn't update the value when a menu item is selected, and the ReportTextField only works for the fir ...

Issue with Laravel 5.7 Autocomplete search: JavaScript unable to recognize the specified route

I've been following a tutorial on this video: https://www.youtube.com/watch?v=D4ny-CboZC0 After completing all the steps, I encountered an error in the console during testing: jquery.min.js:2 POST http://apr2.test/admin/posts/%7B%7B%20('autocom ...

Issues concerning date and time manipulation - Library Moment.js

As a beginner in JavaScript, I've been working on an activity that generates a table of train times based on user input. However, I'm facing issues with formatting the arrival time correctly. Whenever I input the arrival time in military format ( ...

Node and Angular Error: The specified file or directory does not exist

I have been using the tutorial from scotch.io to build my first node and angular application. I encountered a common issue with relative paths online resulting in the error message Error: ENOENT: no such file or directory. However, after following the tuto ...

Retrieve the keys stored within a complex array of objects

I am searching for a function that can transform my data, specifically an array of objects with nested objects. The function should only include keys with immediate string/number/boolean values and exclude keys with object/array values. For example: [ { ...

Please include the document with a name that contains spaces

I am facing an issue where I cannot attach files with spaces in the name. However, when a file with no space in the name is successfully attached. I am using CodeIgniter for this purpose, uploading the file to the server before attaching it. I use the help ...

Tool for controlling the layout of the viewport with Javascript

I have experience using ExtJS in the past to create dashboards, and one of my favorite features is the full-screen viewport with a border layout. This allows for easy splitting of a dashboard into panels on different sides without creating excessive scroll ...

Error message: The login buttons from Meteor's accounts-ui-bootstrap-3 are not showing up on the webpage

Following the installation of bootstrap-3 and accounts-ui-bootstrap-3, the expected ui-accounts login widget was not displayed when using {{ loginButtons }}. Instead, a <div> appeared in place of the widget, with no actual widget visible. Are there ...

Issue with Twilio's sendMessage function: it is not successfully delivering messages to every value within

I am encountering a problem with Twilio failing to send a message to all the values in an array. var index; var a = req.body.numbers; console.log(a); if (req.body.numbers.indexOf("undefined") > -1) { console.log("No numbers stored"); } else { for ...

The webpage displays the element as <span class="icon">&#xe80d;</span> instead of rendering it properly

In my ReactJS project, I have created a component called Menu1item: class Menu1item extends React.Component{ render(){ return ( <div> {this.props.glyph}{this.props.value} </div> ) ...

What is the best method of transferring all procedures from frida javascript rpc.exports to python?

I have a JavaScript file containing rpc.exports rpc.exports = { callfunctionsecret: callSecretFun, callfunctionsomethingelse: callSomethingElse, } I am trying to retrieve a list of all these functions in Python, but I have been unable to find a so ...

What advantages does event delegation in JavaScript offer compared to using jQuery's event handling?

Vanilla JavaScript: parentNode.addEventListener("click", function(event) { if (event.target === childNode) { code here } }); versus jQuery: $(parentNode).on("click", childNode, function() {}); ...

What are the best strategies for handling complex task operations in Node.js Express.js?

How can I effectively manage lengthy task functions in Node.js Express.js to prevent timeout errors? Currently, my application includes a time-consuming function that does not require an immediate response but still needs to execute its tasks. How can I en ...

Adjust the width of a div within a nested iframe using jQuery without the need for an identifying ID on the iframe itself

Below is the code sample I'm working with: <iframe> <div id="inner_div"> Here's some text! </div> </iframe> I am aware that by adding an id to the iframe, I could follow the instructions provided here to access t ...

Attempting to create distinct match matchups for every team in a manner reminiscent of the Swiss system format used in the 2024/25 UEFA Champion League

I've been working on devising a tournament pairing system modeled after the updated UEFA Champion League structure. The league phase involves 36 teams, categorized into 4 different pots. Each team is scheduled to play a total of 8 matches against 2 op ...

Which directives in AngularJS facilitate one-way binding?

Which directives in AngularJS support one-way binding? While ng-model enables two-way binding, what about ng-bind and {{ }} expressions - do they also support one-way binding? ...

The Highcharts Range Selector feature may encounter issues when used with multiple series

Currently, I am facing an issue with my highchart/highstock where I retrieve data from a PHP file. The problem arises when I attempt to use multiple series as the RangeSelector Buttons cease to function properly. For instance, in the example provided, the ...

Once the post has been saved to the database, how can I redirect to a different EJS page?

Is there a way to load another page after submitting a post in node.js with ejs? //router function router() { ticketRouter.route("/create/submit") // connected to submit from specific ejs file .post(dataControllerThatHandlesSubmission) // functio ...

Automatically reloading POST request when browser back button is pressed

Our web application is built on Spring MVC and Thymeleaf. When a user lands on the home page with a GET request, they enter 2 parameters and submit a POST request. After successful submission, they are directed to another page (let's call it page2) wi ...