Troubles with a Chrome Extension for JSON

I'm currently working on a project to develop a Google Chrome extension and I've encountered an obstacle. I'm experimenting with JSON data (with the intention of integrating it with an API in the future). I have a sample JSON file, successfully loaded it into my code, and stored the parsed JSON as a variable. However, I'm unsure how to access specific values within the objects.

var xhr = new XMLHttpRequest();
var resp;
xhr.open("GET", "eg.json", true);
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
    resp = JSON.parse(xhr.responseText);
  }
}
xhr.send();

After executing the send request, the object resp takes on the appearance shown here.

As someone who is relatively new to JavaScript, I'm struggling to figure out how to retrieve the createdDate value as a String variable. Any assistance would be greatly appreciated!

Thank you

Answer №1

To access the information, you can utilize either the dot or bracket notation in JavaScript, depending on the scenario. It is recommended to use bracket notation for dynamic properties. An example based on the provided image is as follows:

var registrationDate = resp.WhoisRecord.audit.registrationDate;

It is important to note that this code should be called within the specific if statement where resp is defined. The data will only be populated inside that callback function during the xhr.onreadystatechange assignment. Attempting to use it outside of this context may result in it not being ready when executed.

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

using the information from the child array within a v-if condition

I'm struggling to extract data from a child array and utilize it in my v-if condition. Below are my data and code. Any assistance would be appreciated, even if it's just pointers to the right documentation. <div class='post' v-for= ...

Transitioning from using lerna to adopting pnpm

We are in the process of transitioning our project from Lerna to PNPM and we currently have a script that we run. Here are the commands: "postinstall": "npm run bootstrap" "bootstrap": "lerna bootstrap --hoist", &quo ...

Changed over to a promise-oriented database, causing my login feature to malfunction completely

Although I can successfully register, when I am redirected to my game route, all I see is a blank Error page with [object Object] on the screen. This message also appears in my console periodically. Initially, I suspected an issue related to socket.io, bu ...

Guide to automatically updating a table with AJAX requests

My task involves utilizing AJAX to request a random string consisting of 10 numbers from an asp page. The numbers must be delimited by "||" and displayed in a table format. The table is designed to showcase only the top 10 results, with each new row addin ...

Retrieve the request body in Node.js Express server-side code in order to receive an array passed from the front end

I am facing an issue where I need to save a user's array to mongo. When the data passes through the bridge and reaches the posts, it appears as a strange object with string versions of its indices. I am attempting to convert it back into a normal arra ...

Help with enabling the recognition of backspace key in JavaScript?

My current JavaScript is almost perfect but missing one key element. The form has two fields that are disabled when the user fills it out. <label>Can you drive? </label> <input type="booleam" id="drive" disabled><br> <label>W ...

Saving a collection of unique identifiers in Firebase

Struggling to find a solution for organizing Firebase data: Each user has posts with generated IDs, but how do I store these IDs in a user node efficiently? Currently using string concatenation and treating them like a CSV file in my JS app, but that feel ...

Using Gson to Serialize an Array List Containing Objects with Inheritance

I am completely new to using Gson and Json. I have some basic Events that I need to serialize through Json using Gson in Kotlin. Note: The code is written in Kotlin. public abstract class Event() { } public class Move : Event() { var from: Point ...

What is the most effective method for updating a className in Next.js using CSS Modules when a button is activated?

Looking to create a responsive navigation bar that transforms based on screen size? When the width reaches 600px, I'd like to hide the links and instead show a clickable nav button that reveals those options. Upon inspecting my list elements in the c ...

Tips on retrieving a value nested within 3 layers in Angular

In my Angular application, I have three components - A, B, and C. Component A serves as the main component, Component B is a smaller section nested inside A, and Component C represents a modal dialog. The template code for Component A looks something like ...

Conceal the parent element if there are no elements present within the child element

Look at the markup provided: <div class="careersIntegration__listing" id="careers-listing"> <div class="careersIntegration__accordion"> <div class="careersIntegration__accordion-header"> <span class="careersIntegrat ...

An AngularJS-powered dynamic navbar

Apologies if my explanation is unclear, but I am struggling to find a simple way to convey the following information. I have set up a navigation bar that displays different categories of articles. These navigation items are pulled from a database and can ...

Can Pug Templating handle iterating through multiple arrays within a JSON data object?

Exploring Pug for the first time, I have been utilizing JSON files to store the data used in my Pug file. Here is an example of my data structure: { "nav": { "titles": [ "location", "reservations", "accomodations", "ameniti ...

The middleware code remains dormant and is left untouched

I am encountering an issue with this code that is supposed to create a folder if it doesn't already exist. When I debug and set a breakpoint on fs.mkdir, the code does not enter into it. Do you have any idea what could be causing this problem? ... ap ...

Unable to interpret data from JSON file

I have written the following code to read a JSON file. It is not throwing any errors, but I am receiving a null value in the variable: var myData = null; $.ajax({ type: 'GET', async: false, url: 'myJson.json', dataType: ...

Exploring the possibilities of utilizing JavaScript within TypeScript

My dynamic javascript object holds all the resources (translation strings) for my app. Here's how it is structured: var ResourceManager = (function () { function ResourceManager() { var currentLanguage = $('#activeLanguage').htm ...

The functionality of the document download button using Express.js and node.js appears to be malfunctioning

For my current project, I am aiming to enable users to effortlessly download a document by simply clicking on a designated button. Project Outline: public/client.js console.log('Client-side code running'); const button = document.get ...

Tips for utilizing json_decode to extract specific data within a JSON structure

Hi, I have recently started learning php and I am looking for some quick assistance with json_decode/php. Specifically, I need help retrieving the values of g91 in an array. Is there a recursion value that can be passed to json_decode for this? { "e": ...

Error 404 when Making an Ajax Request in Yii2

I'm trying to implement AJAX in Yii2 (a PHP framework) but I am facing issues with the following code. This is my view file (PHP): <script> var url1='<?php echo Url::toRoute('Agehi/Ajaxshahr'); ?>'; </script> & ...

Ensure the presence of an editable column within a table using a jQuery function

Within the table, the first column is editable. Upon making a change to it, I want an alert to appear indicating that a change has occurred. The check function is being called after a delay of 5000ms. Embedding Code Snippet for Reference I suspect there ...