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

React.js: The specified element type is not valid:

I am currently working on a sample project using react.js in Visual Studio 2019 Here is my Index.js file: import 'bootstrap/dist/css/bootstrap.css'; import React from 'react'; import ReactDOM from 'react-dom'; import { Provi ...

Error encountered: The token transfer cannot be completed due to an invalid address

Whenever I attempt to send a token from one address to another, I keep encountering the error mentioned in the title. Below is the relevant snippet of my JavaScript code: tokenContract.transfer($("#targetAddr").val().toString(), $("#amt" ...

Issue in Classic ASP/VBScript: Inconsistently generates incorrect ID post insertion

I've been tasked with creating a web application for a fundraising event at work, where users can make donations through PayPal. Initially, I decided to repurpose an old Classic ASP/VBScript project from over a decade ago and use an Access database. A ...

What steps can I take to ensure the reset button in JavaScript functions properly?

Look at this code snippet: let animalSound = document.getElementById("animalSound"); Reset button functionality: let resetButton = document.querySelector("#reset"); When the reset button is clicked, my console displays null: resetButton.addEvent ...

Instructions on utilizing the signUp() function in Supabase for including extra user details during the registration process

My latest project involves building a Vue.js application with authentication using Supabase. I've been trying to implement the signUp() method from Supabase in order to collect extra user data during the sign-up process. In my code, I added a property ...

Resolving DataTables Error

Here is my JavaScript code snippet. <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.2.1/css/but ...

TS1057: It is required that an async function or method has a return type that can be awaited

There was a recent Github issue reported on March 28th regarding async arrow functions generating faulty code when targeting ES5, resulting in the error message: TS1057: An async function or method must have a valid awaitable return type You can find t ...

Updating post meta in WordPress using AJAX is a simple and efficient task

I have this code snippet: <form method='post'> <input type='submit' name='bid' value='Place Bid'> When the user clicks the submit button, I want to update the post meta in WordPress to adjust the bid va ...

Increase or decrease values in an input field using Vue3 when typing

I am looking to implement a feature where users can input numbers that will be subtracted from a fixed total of 100. However, if the user deletes the input, I want the difference to be added back to the total of 100. Despite my attempts, the subtraction wo ...

Is it time to refresh the sibling element when it's selected, or is there

I have recently started working with react and TypeScript, and I am facing some challenges. My current task involves modifying the functionality to display subscriptions and transactions on separate pages instead of together on the same page. I want to sh ...

What’s faster: Waiting for delayed ajax responses or using sockets in Node.js

In order for my multiplayer game to update a client when another player joins the game, I have considered the following options: Implementing a socket connection Sending Ajax requests at regular intervals Another idea that has crossed my mind is using d ...

NodeJS and ExpressJS fail to redirect to the main landing page

I am currently developing a shopping cart application using nodejs/expressjs. I have encountered an issue with redirecting back to the homepage ('/') after the user submits their credentials during sign up. Despite my search for relevant articles ...

Can I keep using ng-repeat multiple times in my code?

Working on a AngularJS application that involves handling a complex JSON file with multiple nested arrays and objects. My query is: Is it appropriate to use ng-repeat repeatedly for accessing the data from the JSON? <div ng-repeat="parent in parents"&g ...

Button from Material-UI vanishes upon being clicked

I encountered an issue with a button that disappears when clicked on. Additionally, clicking the button once does not trigger any actions associated with it. In order to execute the button actions, I have to click the area where the button was located afte ...

AJAX request failing to execute the query

Could you please refrain from suggesting the usage of mysqli_* functions or PDO? I am aware of them, but for now, I need to stick with mysql_* functions. The issue I'm facing is that my query is not returning any data. Oddly enough, when I execute the ...

When a class and ID are dynamically applied, the click event may not fire and the CSS may not be applied

Hey everyone, I am facing an issue with declaring id and class when creating a table dynamically. I have tried multiple functions to make my click event work but without success. Can anyone help me with this? Below is the code for my dynamic table where I ...

Is there a workaround for the issue of the NodeJS Web Cryptography API require() being undefined in an unsecure origin (Heroku App)?

My goal is to implement the experimental Web cryptography API (SubtleCrypto) on my Node.js server hosted on Herokuapp. The aim is to encrypt data from a fetch request sent from gitpages to herokuapp, concealing sensitive information from the browser consol ...

Having difficulty retrieving the necessary information for manipulating the DOM using Express, Ajax, and Axios

When working on DOM manipulation based on AJAX calls, I've encountered an issue where the response is being displayed on my page instead of in the console.log output. This makes it difficult for me to view the data and determine what needs to be inser ...

Refreshing pane content within Kendo UI Splitview

I am utilizing the Kendo UI splitview. In my setup, I have configured one pane on the left for navigation and another pane on the right for content display. The left pane contains 4 navigation links structured as follows: <div data-role="pane" id="si ...

Stop Code Execution || Lock Screen

Is there a way to address the "challenge" I'm facing? I'm an avid gamer who enjoys customizing my game using JavaScript/jQuery with Greasemonkey/Firefox. There are numerous scripts that alter the DOM and input values. In my custom script, I hav ...