Enabling CORS on the client side

前端 未结 2 596
野趣味
野趣味 2021-01-24 18:44

I\'m creating a web appliacation that will run on a server that I can not manage nor modify in any case.

Within that application, I need to exceute a AJAX call to a dif

相关标签:
2条回答
  • 2021-01-24 19:14

    If the server you are calling does not support CORS, you will not be able to make the request to the third-party server using AJAX.

    You will have to resort to setting up a pass-through AJAX route in your application. The client (browser) makes a request to your AJAX route which proxies the call to the third-party server and returns the result. Because the third-party request is happening on the server rather than the browser, Same Origin Policy doesn't apply.

    This approach means there will be an additional request that wouldn't be necessary if you could use CORS, but there really isn't another option.

    0 讨论(0)
  • 2021-01-24 19:30

    CORS is an option with the SERVER. In no way client can by themselves enable CORS.

    If client would have been allowed to do that, the whole purpose of CORS would be defeated.

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