{"id":375,"date":"2011-09-20T03:42:51","date_gmt":"2011-09-20T03:42:51","guid":{"rendered":"http:\/\/www.nirvaat.com\/?p=375"},"modified":"2011-11-01T06:49:05","modified_gmt":"2011-11-01T06:49:05","slug":"working-with-access-control-allow-origin","status":"publish","type":"post","link":"https:\/\/nirvaat.com\/blogs\/2011\/09\/working-with-access-control-allow-origin\/","title":{"rendered":"Working with Access-Control-Allow-Origin"},"content":{"rendered":"<p>When developing Ajax applications on local machine you may face this error on almost all browsers that cross referring a link from other domain is not allowed. This is mentioned as the &#8220;Access-Control-Allow-Origin&#8221; on Google Chrome. To work around this issue, temporarily &#8211; yes temporarily as this may make your system unsafe &#8211; you need to run Chrome with following argument &#8211; &#8220;&#8211;disable-web-security&#8221;.<\/p>\n<p>On Linux you can use the following command to sun Google Chrome with web security disabled &#8211;<\/p>\n<p><code>\/usr\/bin\/google-chrome --disable-web-security<\/code><\/p>\n<p>On Windows machine you can create a shortcut to Google Chrome and add the above mentioned flag in the command line.<\/p>\n<p>Please remember that do not use your browser for browsing non-trusted sites in this mode. Only use this for testing and development purpose only. This is for your security only.<\/p>\n<p><strong>Update:<\/strong> If you have access to the file server which you are accessing from a different server, then you can use &#8220;.htaccess&#8221; directive also to allow access from a domain or all domains.<\/p>\n<p><code>&lt;IfModule mod_headers.c&gt;<br \/>\nHeader set Access-Control-Allow-Origin \"*\"<br \/>\n&lt;\/IfModule&gt;<br \/>\n<\/code><\/p>\n<p>Suppose you are accessing file &#8220;xyz&#8221; hosted on server &#8220;One&#8221; from server &#8220;Two&#8221; then you need to add the .htaccess directive in the directory of the server &#8220;One&#8221; to which you want to allow remote access.<\/p>\n<p>To restrict the access from specific domains only you can specify the domain name(s) in place of &#8220;*&#8221; separated with comma like &#8211; <code>http:\/\/yoursite.com,http:\/\/anothersite.com.<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When developing Ajax applications on local machine you may face this error on almost all browsers that cross referring a link from other domain is not allowed. This is mentioned as the &#8220;Access-Control-Allow-Origin&#8221; on Google Chrome. To work around this issue, temporarily &#8211; yes temporarily as this may make your system unsafe &#8211; you need [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"categories":[29,26,4],"tags":[55,53,54],"class_list":["post-375","post","type-post","status-publish","format-standard","hentry","category-blog","category-quick-fixes","category-web-development","tag-access-control-allow-origin","tag-chrome","tag-web-security"],"_links":{"self":[{"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/posts\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":3,"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/posts\/375\/revisions\/384"}],"wp:attachment":[{"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nirvaat.com\/blogs\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}