Using JavaScript to extract data from a JSON-formatted URL

I am currently facing a challenge with parsing JSON data from a specific URL. Despite my efforts, I am unable to retrieve any information related to the "ask" and "bid" values from this JSON feed. The URL in question is .

The structure of the JSON data is as follows:

{
EURUSD: {
dir: 1,
ask: "1.13960",
bid: "1.13955"
},
USDJPY: {
dir: 1,
ask: "118.928",
bid: "118.925"
},
USDCHF: {
dir: 1,
ask: "0.94488",
bid: "0.94459"
},
GBPUSD: {
dir: 1,
ask: "1.54351",
bid: "1.54342"
},
AUDUSD: {
dir: 0,
ask: "0.77653",
bid: "0.77648"
},
NZDUSD: {
dir: 1,
ask: "0.75169",
bid: "0.75158"
},
GBPJPY: {
dir: 1,
ask: "183.564",
bid: "183.553"
},
EURGBP: {
dir: 1,
ask: "0.73836",
bid: "0.73829"
}
}

This is the JavaScript code that I have been using:

$.getJSON("http://www.fxgrow.com/quotes/quotes.php", function(data) {
    alert(data.msg);
});`

Answer №1

Here is the link to the JSFIDDLE: http://jsfiddle.net/yumq1mzu/1/

To bypass web security in Chrome, you can clone the shortcut from your desktop and add the parameter --disable-web-security at the end of the chrome executable path like so:

"C:\Program Files\Google\Chrome\Application\chrome.exe" --disable-web-security

After restarting Chrome, update your code as follows:

$.getJSON("http://www.fxgrow.com/quotes/quotes.php", function(data) {
    alert(data.EURGBP.dir);   // alert 1
});

Using the JSON data below:

{
"EURUSD":{"dir":1,"ask":"1.13679","bid":"1.13674"},
"USDJPY":{"dir":1,"ask":"118.995","bid":"118.990"},
"USDCHF":{"dir":1,"ask":"0.94957","bid":"0.94940"},
"GBPUSD":{"dir":1,"ask":"1.54205","bid":"1.54195"},
"AUDUSD":{"dir":1,"ask":"0.77893","bid":"0.77887"},
"NZDUSD":{"dir":1,"ask":"0.75185","bid":"0.75175"},
"GBPJPY":{"dir":1,"ask":"183.496","bid":"183.483"},
"EURGBP":{"dir":1,"ask":"0.73724","bid":"0.73716"}
}

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

Working with arrays containing numerical keys in JSON using jQuery

If I have a PHP file that generates JSON data with numerical keys like this: <?php $array[1] = "abcd"; $array[2] = "efgh"; $array[3] = "1234"; $array[4] = "5678"; echo json_encode($array); ?> How can I access the value associated with key 4? The i ...

Is it possible for me to convert a .map array into a comma-separated array enclosed in double quotation marks?

I am attempting to extract data from a group of twig variables and convert them into a javascript plugin. The data consists of dates listed in an array format. Initially, they are displayed on the template as a string like this: {"date":"2018-08-30, 2018- ...

Troubleshooting Issue with InfoWindow Display on Multiple Markers in Google Maps

I'm having trouble getting my markers to show different infowindows. No matter what I do, the markers always display the content of the last "contentString" in the loop. Despite reading through multiple posts on this issue, I haven't been able t ...

Exploring the process of querying two tables simultaneously in MySQL using PHP

I currently have a search box in my PHP file that only searches from the "countries" table. However, I also have another table called "continent" and I would like the search box to retrieve results from both the "countries" and "continent" tables. Here is ...

Can a custom CSS be linked directly to the angular-cli.json file?

I'm trying to incorporate custom CSS into my angular-cli.json file, but I haven't been able to find a successful method. I attempted to use the following code: "styles": [ "styles.css", "http://site.test/mycss.css" ], However, it does ...

Crockford's system for safeguarded entities

Despite the abundance of questions and resources related to "Javascript: The Good Parts," I am struggling to comprehend a specific sentence in the book. On pages 41-42, the author defines the serial_maker function as follows: var serial_maker = function ( ...

The webpage is not refreshing or reloading despite using window.location.href

When creating a refreshcart() function, the window.location.href is assigned to currentUrl. However, when making an ajax call in the else block with window.location.href = currentUrl, true; it does not successfully refresh the page. $(document).ready(fu ...

What is the correct location to define the "env" setting in the eslint.config.js file?

In 2022, ESLint rolled out a new configuration system called the "flat config" here. Check out the documentation for the new "flat config". | Old configuration system documentation here. The "flat config" documentation shows that the `eslint.config.js` ...

Checkbox click event not triggering properly

I am facing challenges in triggering an onclick event for the "Elevation" checkboxes located at the URL provided above. <input type="checkbox" value="A" id="elevation_A" onclick="changeElevation(this.value);" /> For some reason, the "changeElevati ...

The Vue.js v-on:mouseover function is not functioning properly in displaying the menu

When I hover over a LI tag, I want to display a menu. I have successfully implemented it using a simple variable with the following code: @mouseover="hoverFormsControls=true" @mouseleave="hoverFormsControls=false" However, when I attempted to use an arr ...

Ways to extract a specific element from a webpage's body section

When utilizing node-fetch to retrieve the body of a site, I follow this process: import fetch from 'node-fetch'; (async () => { const response = await fetch('link'); const body = await response.text(); console.log(body) ...

Encountering a problem in Django when attempting to serialize decimal points, error message reads: 'ValuesListQuerySet' does not contain the attribute '_meta'

I'm trying to serialize a FloatField model instance in django, specifically within a management command. Here's the code I have: def chart_data(request): i = 1 chart = open_flash_chart() chart.title = t for manager in FusionMa ...

Load the values into the dropdown list based on the selection from the previous dropdown menu

Currently, I am working on implementing cloning functionality for select boxes. There are 3 select boxes: country, state, city. The user selects the country first which then populates the state select box based on the ID, and similarly, the city dropdown ...

Discovering and sorting an array in Vue.js based on IDs

Hello everyone, I've been attempting to filter my results using the filter and includes methods but it doesn't seem to be working. Does anyone have a solution for this, perhaps involving includes or something similar? companies ids [1,2,3] user c ...

Using jQuery to display checkbox text even when it is not directly adjacent to the checkbox

I'm struggling to display the checked value text as shown in the image without any refresh or click. Can anyone offer assistance? This is my PHP dynamic form: <div class="products-row"> <?php $tq=$conn->query("select * from os_tiffen ...

(Is it even necessary to use a timezone library for this straightforward scenario?)

As I delve into the realm of time zones for the first time, I've heard tales of how challenging it can be for developers. To ensure I am on the right track, I am posing this question as a safeguard to make sure nothing is overlooked. My scenario is q ...

Error: React Select input control is throwing a TypeError related to event.target

Having trouble changing the state on change using a React Select node module package. It works with regular text input, but I can't quite get it to work with this specific component. The error message "TypeError: event.target is undefined" keeps poppi ...

Is NoSQL supported by the MySQL Community Edition?

I have decided to dive into learning and developing a Node.js application with SQL. I am aware that the MySQL Enterprise Edition offers support for NoSQL, but I'm curious if the community edition also supports NoSQL or if I need to invest in the enter ...

Transform the display format of the input type date field from 'MM/DD/YYYY' to 'February 5, 2012' in a React.js application using Material-UI's TextField component

https://i.stack.imgur.com/9p7Mz.jpg I am working with a material-ui/ TextField date component and I am looking to maintain the current style and input method, but I need to adjust how the entered value is displayed to the 'en-us' format. const o ...

Generating perspectives from a HashMap contained within an ArrayList

I've been struggling with this logic problem, but I believe I'm getting closer. I am extracting values from a JSON response and storing them in a HashMap before adding the HashMap to an ArrayList. doInBackground protected String doInBackground( ...