0

Which is better to Accessing and displaying data from an external API for a website? I am writing a school report and I am trying to understand the benefits and drawbacks of each when accessing and displaying data.

Scope: jQuery, AJAX, JSON, XMLHttpRequest

Jay
  • 141
  • 3
  • For accessing data, browsers have CORS restrictions, so you might run into problems trying to access 3rd party APIs with AJAX/XMLHttpRequest. Given this restriction, that part of the debate seems moot. – David Tran Apr 17 '20 at 23:10
  • @DavidTran could you please expand on this? – Jay Apr 18 '20 at 09:43
  • Sure. Please take a look at a sample here: [https://codepen.io/54098wejk4/pen/MWajgMa](https://codepen.io/54098wejk4/pen/MWajgMa) When you click the button, it's supposed to send an XMLHttpRequest to an IP geolocation API. If you open up your dev console and click it, you'll see some errors appear because the API is not hosted on the same domain as www.codepen.io. This is a security feature of browsers. Therefore, relying on the client's browser to connect to the 3rd party API isn't going to work, unless you implement some fancy workarounds. – David Tran Apr 19 '20 at 22:28

0 Answers0