Cross-Origin Request block issue fix

Sometime we have to request files from different host using ajax, and it may create problem because of CORS polices.

CORS means Cross-Origin Resource Sharing (CORS).

Cross domain request will be block by most of the browsers due to same-origin security policy. so we have to enable CORS on our server.we can do this by setting
Access-Control-Allow-Origin in a PHP with changing server.

if we need to allow a request from a perticular domain we can restrict as below

 

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

 

or we can allow from all sites

 

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

 9,052 total views,  4 views today

2 Comments

  1. It is actually a nice and useful piece of information. I am satisfied
    that you shared this useful information with us. Please stay
    us informed like this. Thanks for sharing.

  2. whoah this blog is fantastic i really like reading your articles.
    Stay up the good work! You realize, lots of persons are hunting around for this info, you can help them greatly.

Leave a Reply

Your email address will not be published.