Saturday, December 12, 2015

Cross Origin support specially for AJAX request-response.

htaccess file should be configured correctly to tell Apache to receive-send response for cross origin site.
For e.g. we've site www.mysite.com and www.subdomain1.mysite.com. Now we want to send-receive data from subdomain1. In this case we should configure htaccess  properly otherwise response will always be sent to mysite domain even when request is from subdomain1.

Just add these following line of code inside the htaccess and you're done :)

----------------------------
<IfModule mod_headers.c>
    Header add Access-Control-Allow-Origin "*"
    Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
    Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
</IfModule>

----------------------------

No comments:

Post a Comment