Is the XMLHttpRequest Object looking to access a file located one directory above?

My XMLHttpRequest Object is attempting to access a file located outside of its current folder.

According to W3Schools, modern browsers restrict access across domains for security purposes. Both the web page and the XML file being loaded must be on the same server.

In my case, the file is on the same server but in a different directory. Despite using "../" syntax to indicate that it's one level up from the folder, I'm unable to read the file. Is there a workaround for this issue?

The javascript file functions perfectly when the .xml file is in the same folder, yet I aim to access it from a higher directory - one level up. Using "xmlhttp.open("GET", "../myFile.xml", true);" doesn't grant access to the file.

1. Successfully loads myFile.xml from the current folder.

2. Fails to locate myFile.xml in the parent directory of the folder.

Even specifying the direct path doesn't work as expected.

[EDIT - Update] Issue resolved after transferring files to the host server from the desktop folder. Still unsure why there was a discrepancy between desktop environment and server, but relieved to know the code was correct.

Answer №1

Currently, I'm working from my desktop and organizing files within a folder on the same desktop.

Most web browsers have restrictions in place that prevent XMLHttpRequest from accessing file: URIs.

Although Firefox does allow access with certain limitations:

A file is only able to read another file if it resides in a directory above the originating file's parent directory.

Since the file you are attempting to retrieve is located in a directory higher than the HTML document's directory, access permission is refused.

To bypass this limitation, refrain from using XMLHttpRequest without utilizing HTTP instead.

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

New color scheme in Visual Studio Code for JavaScript and TypeScript files within Visual Studio 2017

I am interested in importing or setting a Visual Studio Code color theme for JavaScript and TypeScript files in Visual Studio 2017. Specifically, I would like to customize the color theme for files with extensions: .js, .jsx, .ts, and .tsx. If individual f ...

What is the correct method for retrieving values from a JSON array?

To extract information from a JSON file, I have created a function as shown below: function getarray(){ $http.get('http://localhost/prebuilt/countries.json') .success(function(data) { $scope.countries = data; }); return data; } Howe ...

incorporate information into D3 with React

Greetings! I am currently working on a line graph that should display dynamic data. In cases where no data is provided, it will simply show a straight line. My current challenge lies in passing the props to the line graph component. var data `[ { &quo ...

Encountering issue while static generating project: Cannot find resolution for 'fs' module

I am encountering an issue in my Next.js app when trying to serve a static file. Each time I attempt to use import fs from 'fs';, an error is thrown. It seems strange that I have to yarn add fs in order to use it, as I thought it was not necessa ...

Looking for a jQuery function that will display the hidden list items once a successful login has been completed

<li id="liAfterLogin" runat="server" style="display:none;"><a class="drop" href="#">Articles</a> <ul> <li><a href="Category.aspx">Categories</a></li> <li><a href="PopularArticles.aspx"> ...

Creating a dynamic `v-model` for computed properties that is dependent on the route parameter

I am creating a versatile component that can update different vuex properties based on the route parameter passed. Below is a simplified version of the code: <template> <div> <input v-model="this[$route.params.name]"/> </div&g ...

What is the best way to display SVGs from an API response using next/image or the <img> tag in Next.js?

I have a collection of SVGs being returned from an API response, which I am fetching inside the useEffect. The response structure is as follows: {svg1: 'https://remoteserver.com/assests/svg1.svg', ...and so on} (These SVGs are not static assets ...

What could be the reason behind the AJAX request not posting data to the controller?

I've been working on sending data to a controller using ajax, but instead of successfully posting the data, I keep getting redirected to a different URL. @section CustomScripts { <script type="text/javascript"> function ...

What is the best method to retrieve the correct object from a dynamic array based on the name and value of a text field?

I'm having trouble dynamically changing the values in an array as I type and submit textfields. I've tried linking the exercise key to the necessary values, but it's not working. Below is the main function: export default class AddWorkoutF ...

What is the method for invoking a component with an event in Vuetify?

Currently, I am working on implementing a SnackBar component on my website. The requirement is that the snackbar should appear when the user clicks the submit button. How can I pass my snackbar component to the button inside my Add.vue file? I want to be a ...

Looking for a way to locate any elements in jQuery that do not contain a certain CSS class?

I am looking to target all form elements that do not contain a specific CSS class. For example: <form> <div> <input type="text" class="good"/> <input type="text" class="good"/> <input type="text" class="bad"/> ...

Screen boundary bouncing effect upon reaching the edge

Currently, I am working on an animated project using canvas. I have successfully implemented the functionality to control the image (ship.png) with the arrow keys for different directions. However, I am facing challenges with creating a bounce effect when ...

Steps for generating a fresh type denotation from a value within an object

Is it possible to create a new type alias based on an object's values? const test = { 'a': ['music','bbq','shopping'], 'b': ['move','work'] }; How can we extract this information f ...

Encountering an issue with Angular build in Docker: [ERR_STREAM_DESTROYED] - Write function cannot be called after a stream

Below is the docker file I'm using to build my Angular project: FROM node:12-buster-slim as build-step RUN mkdir -p /app COPY . /app WORKDIR /app RUN chmod 777 -R /app RUN npm install ARG configuration=production RUN npm run build -- --output-path=./ ...

When receiving a GET response after a server crash

Question: I am sending a Get request through Ajax every second and waiting for a response from the server. However, if my application crashes and I keep sending requests every second, I only receive a server timeout error (HTTP status code 502) with no oth ...

Tips for directing the scroll according to the current selection class

I am attempting to focus the scroll based on the selected class when clicking on the previous and next buttons. How can I achieve this functionality? Please review my code on https://jsfiddle.net/kannankds/bcszkqLu/ <ul class="kds"> <li>tile ...

JavaScript function for validating CGPA or GPA fields

I am encountering issues with JavaScript validation in ASP.NET. The validation seems simple, but for some reason, it is not functioning properly. Below is the code that I have tried: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.as ...

Toggle a button with javascript

My setup involves two switches: <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="switch1" checked> <label class="onoffswitch-label" for="switch1"> <span class="onoffswitch-inner"></span> <span ...

Guide on utilizing `ReactCSSTransitionGroup` for developing an expandable/collapsible list

Utilizing ReactJS to implement a collapsible/expandable list with animation has been my latest endeavor. To access the code, simply visit this link. Upon clicking the Extend button located at the top of the list, I anticipate the items to appear within 1 s ...