I am attempting to retrieve JSON data from bitbns.com, however I am encountering an issue

Being new to javascript, I recently attempted to retrieve json data from bitbns but encountered the error - "(Reason: CORS header ‘Access-Control-Allow-Origin’ does not match ‘’)."

I scoured the internet in search of a solution, but unfortunately came up empty-handed.

<script>

url = "https://www.bitbns.com/order/getTicker";
var request = new Request(url);

fetch(request, {mode: "cors",
}).then(function(response) {
       return response.json();
    }).then(function(j) {
       console.log(JSON.stringify(j)); 
    }).catch(function(error) {  
        console.log('Request failed', error)  
    });
console.log(request.headers)
</script>

Would greatly appreciate any assistance with this issue.

Answer №1

const proxyServer = 'https://cors-anywhere.herokuapp.com/'
const endpoint="https://www.bitbns.com/order/getTicker";
let fullUrl = proxyServer + endpoint
fetch(fullUrl, {mode: "cors",
}).then(function(response) {
       return response.json();
    }).then(function(data) {
       console.log(JSON.stringify(data)); 
    }).catch(function(error) {  
        console.log('Request failed', error)  
    });

This code snippet is a good starting point, but should not be used in production environments due to security risks.

provides a method to add CORS headers.

Answer №2

After researching, I came across an informative post on cross-origin CORS requests

$.ajax({
            url: 'http:ww.abc.com?callback=?',
            dataType: 'JSONP',
            jsonpCallback: 'callbackFnc',
            type: 'GET',
            async: false,
            crossDomain: true,
            success: function () { },
            failure: function () { },
            complete: function (data) {
                if (data.readyState == '4' && data.status == '200') {
                    errorLog.push({ IP: Host, Status: 'SUCCESS' })
                }
                else {
                    errorLog.push({ IP: Host, Status: 'FAIL' })
                }
            }
        });

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

When the React application loads, loadingbar.js will be mounted initially. However, as the props or states are updated, the object

I recently made the switch from using progressbar.js to loadingBar.js in my React application for widget progress. Everything was working smoothly with progressbar.js, but once I switched to loadingBar.js, I encountered a strange issue. After the page load ...

Limit the width and height of MUI Popper with a maximum setting

After experimenting with the popper API from MUI, I discovered that it extends beyond my main div. Does anyone have suggestions on how to prevent this overflow? I am looking to increase the height of the popper. Please refer to the code snippet below: con ...

Encountered an issue while attempting to create a Higher Order Component using React and

Encountered an issue while using recompose to create a Higher Order Component (HoC) with withState and lifecycle: warning.js?8a56:36 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM eleme ...

How can I update getServerSideProps using a change event in Next.js?

Currently, I am faced with the task of updating product data based on different categories. In order to achieve this, I have set up an index page along with two components called Products and Categories. Initially, I retrieve all products using the getServ ...

Tips for locking the button in the navigation bar while scrolling

I noticed that when I have 6 fields in my navbar, with 5 of them being links and one as a dropdown, the scrolling of the page causes all fields to remain fixed except for the dropdown field.Check out this image description for reference https://i.stack.im ...

Automatically execute JavaScript upon loading the page with the option to value run on

Upon loading the page, Week 1 is automatically selected which is great. However, the javascript function only runs when I manually choose an option. I want the javascript to automatically trigger for week 1 without needing manual selection. Any ideas on ...

I attempted to retrieve a PHP file in my HTML document using AJAX, however, the scripts embedded in the file are not functioning as expected

I have successfully integrated a php file into my HTML document using AJAX. However, I am encountering an issue with the script tags within the PHP file. These scripts work perfectly when the PHP file is viewed individually, but when called using AJAX, the ...

Challenges Encountered when Making Multiple API Requests

I've encountered a puzzling issue with an ngrx effect I developed to fetch data from multiple API calls. Strangely, while some calls return data successfully, others are returning null for no apparent reason. Effect: @Effect() loadMoveList$: Obse ...

Vuejs: Users can still access routes even after the token has been deleted

Upon logging out of my application, I have encountered a peculiar issue. Certain inner links, such as those within a user's panel, remain accessible even after I have logged out and deleted a token. However, other links are not. Any suggestions on how ...

Encountering a reload error while refreshing the Angular page

Whenever I click on a deck from my list, the corresponding deck-detail component is supposed to load and display the details of the selected deck. The URL should also change to something like "deck/id/deckName". However, if I try to reload the page or copy ...

`Vue JS table with Boostrap styling showcasing a loading indicator for busy state`

Issue: I need to show a loading icon while waiting for the table to load. https://i.sstatic.net/kRCbL.png I am utilizing Boostrap-vue JS, which is built on top of Bootstrap, and VueJS's "b-table" component to display approximately 3000 rows in a tabl ...

When using the <Routes> component, it will not render a component that acts as a container for multiple <Route> elements

Upon wrapping my component in <Routes>, I encountered this warning: Warning: [Categories] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment> In App.js: const App = () => ...

I am unable to produce sound by clicking on the drum machine

My goal is to develop a basic react drum machine project that I discovered on freecodecamp. The objective is to display 9 drumpads and trigger sound upon clicking. Update: I have successfully rendered all the keys but I am facing issues with the function ...

Utilizing JavaScript along with ASP.NET web user controls

My web user control generates specific HTML code on the client side. I am trying to reference a particular RadioButton control using JavaScript. The issue is that the RadioButton ID is dynamically generated by ASP.NET, for example, I assign the ID as 1_R ...

Challenges with extracting and organizing dates using JavaScript regular expressions

My task involves organizing these text rows into specific groups based on certain criteria and names. Il Messaggero Roma 22 settembre 2023 Il Messaggero Roma 21 settembre 2023 Il Messaggero 22 settembre 2023 Il Messaggero 21 settembre 2023 Il Messaggero Ro ...

How can I obtain a JSONObject as a response in REST Client?

I am currently following a tutorial at https://github.com/excilys/androidannotations/wiki/Rest%20API and I'm looking to bypass the JSON to POJO conversion process and instead work with pure JSONObject (or gson's JsonObject). What should I include ...

Fuzzy picture utilizing <canvas>

Working on translating a webgame from Flash to HTML5 with pixel art sprites, I've noticed that the canvas appears blurry compared to Flash where pixels are more defined. <!DOCTYPE html> <html> <body> <canvas id="c" style="bor ...

Encountering the error message "[TypeError]: Unable to access properties of undefined (reading 'prototype')" when utilizing axios post function in next.js

I am encountering an issue while utilizing the next.js app directory and attempting to make a POST request using axios. const submitHandler = async (e) => { e.preventDefault(); try { const {data} = await axios.post('/api/register&ap ...

I'm having trouble getting $.getJSON to function properly

Has anyone encountered issues with the getJSON function in jQuery? function loadJSON(){ console.log("loading JSON") var jsonFile = themeURL+"/map.json" $.getJSON(jsonFile, function(data){ console.log("loaded JSON") $("#infobox").fadeOut(1000 ...

Vercel Build Issue: It appears that the settings you are utilizing are intended for the 'client' module of '@sanity/preview-kit'

Hey there, I'm encountering a strange issue with Vercel deployment related to sanity. The specific error message during the Vercel build is: Error: It appears that you are using settings intended for '@sanity/preview-kit/client', such as &a ...