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

Let's unravel this JavaScript enigma: the code snippet window.confirm = divConfirm(strMessage) awaits

Imagine a scenario where you have an old website with a lot of existing JS code. If a user wants to update all the alert messages to modern, stylish Div-based alerts commonly used in jQuery, YUI, Prototype, etc., there are primarily three types of JS dialo ...

Error in Node JS: When attempting to use "require", a ReferenceError is thrown

After deciding to utilize a MySQL database, I proceeded by installing MySQL using the command npm i mysql. Following the installation, I included the line of code below in order to begin utilizing it: var mysql = require('mysql'); However, upon ...

"How can I update a table in Flask using Chart.js and Pandas

I have developed a basic Flask application that includes a bar chart using Chart.js and a data table displayed below it. Check out the setup below: https://i.sstatic.net/QB6jQ.png (Live view: ) The bar chart I created counts the number of items for each ...

Creating a javascript function to update content on click

Recently, I've been designing a webpage and encountered an issue. I want the text in a specific area to change whenever a user clicks on a link. Below is the code snippet related to the section I want to modify using a JavaScript function. <div id ...

The jQuery selector fails to refresh after the dynamic insertion of new elements

My selector is: $('section#attendance input:last') However, I add another input to section#attendance. I want the selector to target that new element since it should select the last element due to :last. However, for unknown reasons, it does no ...

Displaying an element as a dropdown menu on PrimeVue

I have a challenge with rendering a Dropdown using PrimeVue with the given script: <template lang="pug"> Dropdown#tag(v-model="tag" :options="tags") </template> <script setup> import axios from 'axios&a ...

What is the best way to implement a recursive service call that is triggered automatically at regular intervals?

I came across this code snippet: us.isConnected() .then(function (msg) { er.msg = msg }, function (msg) { er.msg = msg }); $interval(function () { us.isConnected() .then(function (msg) { er.msg = msg }, function (msg) { er.msg = msg }); }, ...

Angular Typescript error: Trying to assign a value to 'someProperty' property of an undefined object

Within my Article class, I have a property called Image which is structured like this: export class Article { public image:Image; public images: Image[]; } If I decide to comment out this.article.image = new Image(); in the following way: constru ...

Steps for displaying the contents of a file from Firebase storage on a React component

I uploaded a file to Firebase storage, and I want my app to be able to access and display the contents of that file within my class component div. Currently, when I try to access the file, it just opens in a new tab instead. class ScanResult extends Comp ...

Manipulate the way in which AngularJS transforms dates into JSON strings

I am working with an object that contains a JavaScript date, structured like this: var obj = { startTime: new Date() .... } When AngularJS converts the object to JSON (for instance, for transmission via $http), it transforms the date into a string as ...

What is the best way to add a new json line to an existing json file?

I'm currently working on a Python project where I need to manipulate a JSON file. with open('..\config_4099.json', "r") as fid: jaySon = json.load(fid) The json file has a flat structure, so there are no internal elements to modif ...

"Modify marker icon upon click event in Google Maps by utilizing the loadGeoJson function

I have successfully loaded the markers from a json file using loadGeoJson. While I am able to SET the marker icon/img on load, I am unsure of how to CHANGE it upon click. Is there a way to target the clicked marker and perform a setIcon or similar action ...

Custom AngularJS menu directive using a JSON file to generate submenus

As a newcomer to angularJs, I am looking to create a dynamic menu with submenus using a .json file. It's important for me to be able to easily add new menus and submenus through the same .json document. <a href="#" ng-repeat="item in menuHeader"&g ...

Utilizing Conditional Logic to Create a Dynamic Menu

I have a navigation menu on my website that is divided into two sections. There is a left panel and a right panel which slide in from the side when their respective buttons are clicked, covering the browser window. The functionality of sliding in the pan ...

Using JavaScript to Show Variables When Clicked

I have been working on populating multiple divs with data stored in variables that change when an image is clicked. Here's a snippet of the code within my tag:</p> <pre><code>function displayName(name){ document.getElementById( ...

Error: Unable to interpret the URL provided in /api/posts/1

When working on my next.js 13 app, I encountered an issue while trying to fetch individual blog data from a local MySQL database. In the src/blog/[id]/page.js file, I have the following component: const BlogPost = async ({ params }) => { const data ...

effectively showcasing information in a datatable by converting JSON data into objects

I am looking for a way to display balance information in datatables, but I have not been able to find a solution yet. <!DOCTYPE html> <html lang="en"> <head> <title>Comment</title> <meta charset="u ...

IE10 has a problem with the height being set to 100%, but it seems to work fine in Quirks mode in IE and all

Check out this page for reference: I've noticed an issue with scrolling in Internet Explorer, while other browsers seem to be fine. Can you help me understand why IE is causing the scroll and how I can fix it? Thank you, Judson Here's the cod ...

Limit the execution speed of a JavaScript function

My JavaScript code is set up to trigger a click event when the user scrolls past a specific element with the class .closemenu. This is meant to open and close a header menu automatically as the user scrolls through the page. The problem I'm facing is ...

Tips for deleting a button from a DataTable file upload feature

I currently have Datatable set up to upload images using the code snippet below: { label: "Images:", name: "files[].id", type: "uploadMany", display: function ( fileId, counter ) { re ...