Wednesday, February 25, 2015

Cross-Origin Request Blocked ?

ERROR : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at the url. This can be fixed by moving the resource to the same domain or enabling CORS.



Solution :

If you are working on web project  and want to get data from different site , Sometime you get such type of error 

" Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at the url. This can be fixed by moving the resource to the same domain or enabling CORS. "

then you have to use .htaccess file 

update code

<FilesMatch "\.(php)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>           




if you havn't    .htaccess file then create a file in root folder and update following code 
Following code for wordpress project please change according to your Project 


# BEGIN WordPress
<IfModule mod_rewrite.c>
  RewriteEngine On

 RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond
   %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]
</IfModule>
<FilesMatch "\.(php)$">
   <IfModule mod_headers.c>   
     Header set Access-Control-Allow-Origin "*"
   </IfModule>
</FilesMatch>
# END WordPress



Enjoy Coding  :) 



comment please :)

2 comments:

  1. could you please reslove in case of javascript includes Ajax,Jquery.

    ReplyDelete
  2. My friend Suggest me this blog and I can say this is the best blog to get the basic knowledge.Thank you so much for this Selenium Training in Chennai

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...