CORS error when jquery ajax request on api

后端 未结 2 619
予麋鹿
予麋鹿 2021-01-13 20:17

I am using jQuery ajax to send request to some API. Due to the CORS policy I got a CORS error on the browser\'s console

Here\'s by code



        
相关标签:
2条回答
  • 2021-01-13 20:54

    The cors error is cross origin request policy maintained by the browser for security. To solve your problem either you will have to allow cors request in your server coding or if you do not have access to the server api code you will have to make the api call from your server to api server

    0 讨论(0)
  • 2021-01-13 21:11

    There are 2 situations -

    1. If you have control over the api code then

      make changes in header and add your origin as well.

    2. If you don't have control to change CORS header that is coming from the api

      you have only one option create a backend code(your own api) in any language you prefer that make an http request and get the data. now use your own api to get data on your frontend.

    0 讨论(0)
提交回复
热议问题