How do I go about adding CORS to a view which is formatted as a JSON data document?

I tried adding it to my .htaccess but I think since Drupal is generating the JSON, it doesn't have any effect. And I cannot find an option other than enabling JSONP to have other sites access these JSON views?

Comments

NicholasS created an issue. See original summary.

ZeiP’s picture

Component: Miscellaneous » Documentation
Status: Active » Fixed

CORS headers can be added using the CORS module: https://www.drupal.org/project/cors

I'll add this to the module README and module description, thanks for the relevant question!

  • ZeiP committed c645a9b on 7.x-1.x
    Issue #2909209 by ZeiP: CORS - Add Allow Origin
    
ZeiP’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

noopal’s picture

hi
I can't get cors to work.
I have added the Cors module
I have put the
url of view | *
I was expecting that any url can access the json view. But I still get
'has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.'

Do I need to change something?

Thanks

ZeiP’s picture

@noopal, please open a new support request in the CORS module issue queue: https://www.drupal.org/project/issues/cors?categories=All