CORS Error: API call in app.js

Hi,

When I use fetch api or ajax call or axios for api call from app.js, all are throwing cross origin error.
May I know how to overcome this

Hi Gokul,

CORS errors depend on the API endpoints/Server that you are trying access/hit, some APIs allow CORS and some APIs block CORS. the most common solution to overcome CORS is to make the HTTP request from a server-side application/Middleware, or use request API which by default is built to avoid CORS issues, .

There are also some unconventional solutions to use proxy in the fetch API like given in the first answer for this stack overflow question,

These are some common solutions to get around CORS and each has it’s on own pros, cons, and limitations. but it is up to you to choose which method you wanted to use based on the needs of your app!

Stay safe and have a great day :slight_smile:

2 Likes

Hello @Gokulaselvan_T. Have you considered using the Request API feature to make your API calls and bypass any CORS issues that might occur when using Ajax from app.js?

1 Like

This topic was automatically closed after 7 days. New replies are no longer allowed.