how to bypass Access-Control-Allow-Origin?

前端 未结 6 1946
闹比i
闹比i 2020-11-22 13:55

I\'m doing a ajax call to my own server on a platform which they set prevent these ajax calls (but I need it to fetch the data from my server to display retrieved data from

6条回答
  •  借酒劲吻你
    2020-11-22 14:21

    Put this on top of retrieve.php:

    header('Access-Control-Allow-Origin: *');  
    

    Note that this effectively disables CORS protection, and leaves your users exposed to attack. If you're not completely certain that you need to allow all origins, you should lock this down to a more specific origin:

    header('Access-Control-Allow-Origin: https://www.example.com')
    

    Please refer to following stack answer for better understanding of Access-Control-Allow-Origin

    https://stackoverflow.com/a/10636765/413670

提交回复
热议问题