You can use jQuery .getJSON() function:

$.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D%27WRC%27&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback', function(data) {
    // JSON result in `data` variable
});

If you don't want to use jQuery you should look at this answer for pure JS solution.

Answer from Dan Barzilay on Stack Overflow
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ API โ€บ Request โ€บ json
Request: json() method - Web APIs | MDN
November 7, 2025 - const obj = { hello: "world" }; const request = new Request("/myEndpoint", { method: "POST", body: JSON.stringify(obj), }); request.json().then((data) => { // do something with the data sent in the request });
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ API โ€บ Response โ€บ json
Response: json() method - Web APIs | MDN
When the fetch is successful, we read and parse the data using json(), then read values out of the resulting objects as you'd expect and insert them into list items to display our product data. ... const myList = document.querySelector("ul"); const myRequest = new Request("products.json"); fetch(myRequest) .then((response) => response.json()) .then((data) => { for (const product of data.products) { const listItem = document.createElement("li"); listItem.appendChild(document.createElement("strong")).textContent = product.Name; listItem.append(` can be found in ${product.Location}. Cost: `); listItem.appendChild(document.createElement("strong")).textContent = `ยฃ${product.Price}`; myList.appendChild(listItem); } }) .catch(console.error);
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Learn_web_development โ€บ Core โ€บ Scripting โ€บ JSON
Working with JSON - Learn web development | MDN
To obtain the JSON, we use an API called Fetch. This API allows us to make network requests to retrieve resources from a server via JavaScript (e.g., images, text, JSON, even HTML snippets), meaning that we can update small sections of content without having to reload the entire page.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ javascript โ€บ wc3qbk0b โ€บ javascript-fetch-json-example
How do I fetch JSON using JavaScript Fetch API?
For many programming languages, including JavaScript, Java, C ++, C #, Go, PHP, and Python, there are ready-made code libraries for creating and manipulating JSON data. JSON file names use the .json file extension. ... The Fetch API presents a new global fetch() method, which allows network requests to be made similarly to the XMLHttpRequest (XHR) method but more powerfully and flexibly.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json_http.asp
JSON XMLHttpRequest
AJAX Intro AJAX XMLHttp AJAX Request AJAX Response AJAX XML File AJAX PHP AJAX ASP AJAX Database AJAX Applications AJAX Examples JS JSON
๐ŸŒ
Medium
medium.com โ€บ @yuvaraj.io โ€บ lesson-57-http-requests-responses-and-json-in-javascript-a87754fd4788
Lesson 57: HTTP Requests, Responses, and JSON in JavaScript | by Yuvaraj S | Medium
December 14, 2025 - โœ… This code sends a GET request, receives JSON data, and displays it on the page. JSON (JavaScript Object Notation) is the format most APIs use to send data.
๐ŸŒ
ZetCode
zetcode.com โ€บ javascript โ€บ jsonurl
JavaScript JSON from URL - Fetching Data Explained
October 18, 2023 - Learn how to fetch JSON data from a URL in JavaScript using Fetch API, JQuery, and XMLHttpRequest, with examples and explanations.
Find elsewhere
๐ŸŒ
JSON Editor Online
jsoneditoronline.org โ€บ home โ€บ data-fetching โ€บ post-json
How to POST JSON data in JavaScript | Indepth | JSON Editor Online
February 8, 2023 - In this article, we explored the ... In a JavaScript web application, you can use the built-in fetch function, or use a more feature rich library like Axios to make requests....
๐ŸŒ
CoreUI
coreui.io โ€บ answers โ€บ how-to-send-json-in-a-fetch-request-in-javascript
How to send JSON in a fetch request in JavaScript ยท CoreUI
November 6, 2025 - Set Content-Type header to ... the server about the data format. The JSON.stringify() method converts the JavaScript object into a JSON string suitable for transmission....
๐ŸŒ
JSON
json.org โ€บ JSONRequest.html
JSONRequest
April 17, 2006 - JSONRequest.get does an HTTP GET request, gets the response, and parses the response into a JavaScript value. If the parse is successful, it returns the value to the requesting script. In making the request, no HTTP authentication or cookies are sent. Any cookies returned by the server cause ...
๐ŸŒ
jQuery
api.jquery.com โ€บ jQuery.getJSON
jQuery.getJSON() | jQuery API Documentation
Description: Load JSON-encoded data from the server using a GET HTTP request.
๐ŸŒ
Dmitri Pavlutin
dmitripavlutin.com โ€บ fetch-with-json
How to Use fetch() with JSON
January 23, 2023 - Second, set the body parameter with the object's JSON (as a string). ... Take a look at body option value. JSON.stringify(object) utility function stringifies the JavaScript object into a JSON string.
Top answer
1 of 2
1

In your example, the webhook.site service you're attempting to connect to with your JavaScript isn't enabled (by default) with the proper CORS headers that modern browsers respect & enforce to improve user security. The developer console in your browser of choice should point this out to you; the error mine gave back was:

Access to XMLHttpRequest at 'https://webhook.site/5c7a5049-9c5e-4bf7-b1cf-0e05f6503bfa' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

As the error states, the requested resource doesn't respond with any valid Access-Control-Allow-Origin header, which will prevent the POST itself from being fully executed. In webhook.site, you can select the CORS Headers tickbox from the top of the user interface to enable the service to send the proper CORS headers to get this working.

Copylet xhr = new XMLHttpRequest();

xhr.open("POST","https://webhook.site/5c7a5049-9c5e-4bf7-b1cf-0e05f6503bfa",true); // configuration interface at https://webhook.site/#!/5c7a5049-9c5e-4bf7-b1cf-0e05f6503bfa/e14fc471-4bc4-410f-b16a-0755a231fb12/1

xhr.setRequestHeader("Content-Type", "application/json");

let data = JSON.stringify({'eventType' : 'test'});

xhr.send(data);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

2 of 2
-1

I suggest you to use axios, it gonna be something like this and you will get the response from your post request

Copyconst response = await axios.post('https://webhook.site/4530328b-fc68-404a-9427-3f2ccd853066/', {'eventType' : 'test'});
๐ŸŒ
Tania's Website
taniarascia.com โ€บ how to use the javascript fetch api to get json data
How to Use the JavaScript Fetch API to Get JSON Data | Tania Rascia's Website
// Replace ./data.json with your JSON feed fetch('./data.json') .then((response) => { return response.json() }) .then((data) => { // Work with JSON data here console.log(data) }) .catch((err) => { // Do something for an error here }) Note that with Fetch, even a 404 or 500 error will not return an error. Only a network error or a request not completing will throw an error.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ javascript
XMLHttpRequest and JSON - JavaScript - The freeCodeCamp Forum
July 4, 2023 - Hello, I am working on the challenge ... Here is the example code: const req = new XMLHttpRequest(); req.open("GET",'/json/cats.json',true); req.send(); req.onload = function(){ const json = ......
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ javascript โ€บ wzp2hxwh โ€บ javascript-post-request-example
How do I send a POST request using JavaScript?
To post data in JSON format using JavaScript/jQuery, you need to stringify your JavaScript object using the JSON.stringify() method and provide a Content-Type: application/json header with your request.
๐ŸŒ
Code Maven
code-maven.com โ€บ ajax-request-for-json-data
Ajax request for JSON data with vanilla JavaScript
It can be a URL like http://somesite.com/some/page, or it can be without the hostname just /some/page if we want to send the request to the same server where our JavaScript code came from. In either case we can also send parameters by attaching them after the requested URL. Something like this: http://somesite.com/some/page?fname=Foo&lname=Bar ยท The second parameter is expected to be a function which will be called when the response arrives from the server. In our example we expect the response to be a valid JSON string.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ bytes โ€บ using-fetch-api-to-post-json-data-in-javascript
Using Fetch API to POST JSON Data in JavaScript
September 12, 2023 - The response.json() method also returns a Promise that resolves with the result of parsing the body text as JSON. To send a POST request with JSON data using Fetch, we need to pass an options object as the second argument to fetch().