4

I want to get data from a URL

https://api.binance.com/api/v1/ticker/24hr

When I hit this url in POSTMAN using Get type, i get JSON data, but when I hit it with an AJAX call, I get this issue

Failed to load https://api.binance.com/api/v1/ticker/24hr: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://api.binance.com/api/v1/ticker/24hr with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.

This is my code

$.get( "https://api.binance.com/api/v1/ticker/24hr", function( data ) {
  console.log(data);
});

If need be, I can also change my $.get to $.ajax. That won't be an issue.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Ali Zia
  • 3,825
  • 5
  • 29
  • 77
  • 1
    Read some documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS – sjahan Jul 19 '18 at 07:32
  • 1
    First thing $.get and $.ajax are same thing $.get in direct method to call $.ajax with type:"GET" – Ullas Hunka Jul 19 '18 at 07:32
  • 1
    The service you're using is either deliberately or accidentally disallowing AJAX access by not supplying CORS headers in its responses. You can't change that. A bit of Googling finds that other people have had to implement a server-side proxy to access this data. This answer https://stackoverflow.com/questions/48202982/binance-api-and-angular-4-httpclient is related. – peeebeee Jul 19 '18 at 07:34
  • 1
    https://stackoverflow.com/questions/50873764/cross-origin-read-blocking-corb take a look – Ullas Hunka Jul 19 '18 at 07:35
  • See the *How to use a CORS proxy to get around “No Access-Control-Allow-Origin header” problems* section of the answer at https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe/43881141#43881141 – sideshowbarker Jul 19 '18 at 10:50

0 Answers0