AJAX Cross-domain on symfony2

后端 未结 1 363
小蘑菇
小蘑菇 2021-01-23 21:42

I am building an app with Symfony2 and React. Currently I am trying to fetch data to the react frontend via AJAX calls. No matter what I decide later, I need to know how can I c

1条回答
  •  清酒与你
    2021-01-23 21:56

    The Response of the server need to have the header Access-Control-Allow-Origin (More info here). As Example of a Symfony2 Controller Response with the value * (allowing any origin to access the resource.), you can build a Response as follow:

        return new JsonResponse($data, 200, array('Access-Control-Allow-Origin'=> '*'));
    

    Hope this help

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