Loading external JSON and images located beyond the root directory

Currently, I am attempting to load a JSON file and a set of images from a directory located above my root directory. Although the code I have works, I believe there may be a more efficient way to achieve this.

$.getJSON("http://localhost/folder1/folder2/folder3/content/LB/contents/content.json", function(json){
    console.log(json);
}

as well as images

<img src="http://localhost/folder1/folder2/folder3/content/LB/contents/locations/locationname/thumbnail.png />

I am aiming to load the JSON and images from

http://localhost/folder1/folder2/folder3/content/LB/appdrive/html/someHTML.html
http://localhost/folder1/folder2/folder3/content/LB/appdrive/html/js/someJS.js

Using only HTML, CSS, and JavaScript, my main query is if there is a way to modify the source of the JSON and images to something like this

$.getJSON("folder2/folder3/content/LB/contents/content.json", function(json){
    console.log(json);
}

and the image

<img src="../folder2/folder3/content/LB/contents/locations/locationname/thumbnail.png />

Lastly, it is important to note that FOLDER2 serves as the root directory.

Answer №1

Absolutely! You have the capability to "root" your URLs directly to the website's root by adding a leading slash (e.g., '/directory1/directory2/directory3/.../data.json').

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

Functionality in Three.js that involves selecting nearby objects with an event handler and ensuring that the self object is

I have spent countless hours today diving deep into the documentation, tutorials, and stackoverflow questions in pursuit of a solution to this issue. I am pleading for your assistance – please take pity on me and help! The problem at hand involves a wat ...

Struggling to locate the module: Python, NodeJS, and the fs module

Using Python, I created a script that prompts the user for input (an action). The second option triggers the execution of a NodeJS file named settings.js in a new terminal window: subprocess.call('start node src/settings.js', shell=True) The Nod ...

Change the background color of cells according to the value they contain

I have a scenario where I am populating a table with random numbers, and I want the background color of each cell to change based on the value of the number in that cell. Since these numbers refresh periodically, I need the colors to update accordingly as ...

Why is the col-1 in Bootstrap stacking up instead of flowing horizontally as intended?

Check out my HTML/CSS code below: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <d ...

Using SUM Function and Looping in PHP with MYSQL

Currently, I am focusing on SUM and looping arrays in PHP. Below is the PHP code I have been working on: <?php require_once 'koneksi.php'; if(isset($_POST['id_gejala'])) { $val = $_POST['id_gejala']; for($i="0"; $i ...

Tips for storing a JSON file locally and accessing it at a later time on the client side

Can PHP be used to generate a JSON file containing information like first name and last name? When using json_encode, what is the process of saving it on the client side, and how can it be retrieved and read afterward? ...

Online Adventure - Saving Conversations

I am interested in developing an RPG using JavaScript. The game will involve a significant amount of dialog. While I have knowledge of PHP and MySQL, I am new to XML. My queries are: Would it be more efficient to store the dialog in a MySQL database and ...

Retrieving data from an AJAX dialog with the use of jQuery and ASP.NET

After spending more than a day on this and reading countless posts on the topic, I am still unable to make it work. My goal is to retrieve a value from a textbox (starting with a textbox for testing) in a javascript pop-up in asp.net using js / ajax. Below ...

Discover the effective method in Angular to display a solitary password validation message while dealing with numerous ones

Here is the pattern we use to validate input fields: The length of the input field should be between 6 and 15 characters. It should contain at least one lowercase letter (a-z). It should contain at least one uppercase letter (A-Z). It should contain at le ...

Getting JSON ID from an Array using Python

A customized script was created to extract data from Verizon's connectivity management API. The specific section of the script focuses on retrieving line information based on a search item such as SIM or iccid. Omitted parts of the script involve esta ...

Event Listener for Spelling Quiz Buttons: Check Correct and Incorrect Answers

I am currently in the process of developing a spelling quiz for a project website using HTML, CSS, and JavaScript. The idea is to present the user with a word that has two missing letters indicated by underscores. The user then selects the correct answer ...

Having trouble retrieving text using getText() or getAttribute("innerHTML")

getAttribute but struggling to retrieve the text associated with each combobox. I need to access the text content of every combobox. <small> <input type="checkbox" checked="checked" value="on" name="irOperations[0]"/> Account Activity < ...

Is it possible to iterate over a non-reactive array in a Vue template without having to store it in a data property or computed property?

Presented below is a static array data: const colors = ["Red", "Blue", "Green"]; To display these values in my markup, I can use the following method in React: import React from "react"; // Static array of colors const colors = ["Red", "Blue", "Green"] ...

Is It Possible to Extract a Hidden Document Value from a Web Browser Using IWebBrowser2 in LabVIEW?

After hours of combing through the internet, I've come up empty-handed in my quest to find information related to my current project. I've created an HTML document that gathers user data and stores it in a JavaScript array. This array is then com ...

What is the best way to increase the top padding of an anchor link?

I need to create a padding-top effect for my div when the link to the anchor is clicked: <a href="#myAnchor">Proceed to my anchor</a> ... <div id="myAnchor"> ... </div> The challenge lies in wanting to add the padding only when ...

I can't seem to get the dropdown list to appear. What could be the issue?

I'm currently trying to create a pure CSS dropdown menu on hover by following this tutorial. However, despite multiple attempts, I'm still stuck and in need of some clear explanations for my issue. <div class="navbar"> ...

Refresh the dropdownlist in the ViewBag using AJAX

I am currently developing a cascaded dropdown list where data is passed using dataview. Controller: public ActionResult Index() { ViewBag.States = new SelectList(db.PLStates, "PLStateID", "PLStateName"); ViewBag.Cities = new SelectList(db.PLCitys ...

What could be the reason behind json_encode() omitting the object's functions that were specified?

Recently, I decided to experiment with json_encode for the first time. I created a simple object: class Test { public $action= 'sleep'; public function wake() { $this->action = 'wake'; } } After creating the object, I en ...

What's the best way to constrain a draggable element within the boundaries of its parent using right and bottom values?

I am currently working on creating a draggable map. I have successfully limited the draggable child for the left and top sides, but I am struggling to do the same for the right and bottom sides. How can I restrict the movement of a draggable child based o ...

Combining two objects in node-red: A step-by-step guide

msg.payload : Object object HAMK307: object a_temperature: 23.1 a_humidity: 46 a_brightness: 3703.05 a_lights: "on" a_presence: "empty" r_temperature: 35.59 r_humidity: 30.46 r_pressure: 994.43 a_time: object ID: "HAMK-307" m ...