{"id":833,"date":"2021-05-27T16:11:12","date_gmt":"2021-05-27T15:11:12","guid":{"rendered":"https:\/\/www.kolkataonweb.com\/code-bank\/?p=833"},"modified":"2021-05-27T11:30:14","modified_gmt":"2021-05-27T10:30:14","slug":"cross-origin-or-cors-issue","status":"publish","type":"post","link":"https:\/\/www.kolkataonweb.com\/code-bank\/miscellaneous\/cross-origin-or-cors-issue\/","title":{"rendered":"Cross Origin or CORS Issue"},"content":{"rendered":"<p>We often get the CORS error when we try to run some code from localhost or XAMPP. The following steps will help to solve it. <em>Please note you will need access to server side code or server configurations.\u00a0<\/em><\/p>\n<ol>\n<li>Set <span style=\"color: #0000ff;\">Access-Control-Allow-Origin<\/span> to <span style=\"color: #0000ff;\">&#8220;*&#8221;<\/span> in the code<\/li>\n<li>Set <span style=\"color: #0000ff;\"><span style=\"color: #0000ff;\">Header set Access-Control-Allow-Headers <span style=\"color: #000000;\">to<\/span> &#8220;*&#8221; <span style=\"color: #000000;\">in the code<\/span><\/span><\/span>&nbsp;<\/li>\n<li>If the above didn&#8217;t work then add the same to .htaccess<\/li>\n<li>If still not solved then set the same in Apache \/ HTTPD configuration<\/li>\n<\/ol>\n<p>In my case setting it in the code didn&#8217;t work. So it set it in the .htaccess but it also didn&#8217;t work. I was getting the error &#8220;<span style=\"color: #ff0000;\"><em>Reason: header \u2018access-control-allow-headers\u2019 is not allowed according to header \u2018Access-Control-Allow-Headers\u2019 from CORS preflight response<\/em><\/span>&#8220;. The point to note is CORS Preflight. Which indicated that the error happened before the request reached the code. So I thought to set it in Apache config and it worked.<\/p>\n<p>In my case the server had ISPConfig, so I set it through ISPConfig instead of changing the actual Apache configuration file.<br \/>\nThe configuration needs to be put under <span style=\"color: #008000;\">&#8220;Sites&#8221; -&gt; &#8220;&lt;Site Name&gt;&#8221; -&gt;\u00a0 &#8220;Options&#8221; -&gt; &#8220;Apache Directives&#8221;.<br \/>\n<span style=\"color: #000000;\">The exact lines to be put<\/span><br \/>\n<\/span><span style=\"color: #0000ff;\">Header set Access-Control-Allow-Origin &#8220;*&#8221;<\/span><br \/>\n<span style=\"color: #0000ff;\">Header set Access-Control-Allow-Headers &#8220;*&#8221;<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We often get the CORS error when we try to run some code from localhost or XAMPP. The following steps will help to solve it. Please note you will need access to server side code or server configurations.\u00a0 Set Access-Control-Allow-Origin to &#8220;*&#8221; in the code Set Header set Access-Control-Allow-Headers to &#8220;*&#8221; in the code&nbsp; If&hellip; <a class=\"more-link\" href=\"https:\/\/www.kolkataonweb.com\/code-bank\/miscellaneous\/cross-origin-or-cors-issue\/\">Continue reading <span class=\"screen-reader-text\">Cross Origin or CORS Issue<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,3],"tags":[307,305,306,127,142,309,308],"class_list":["post-833","post","type-post","status-publish","format-standard","hentry","category-miscellaneous","category-php","tag-access-control-allow-origin","tag-cors-error","tag-cross-origin-error","tag-ispconfig","tag-ispconfig-3","tag-ispconfig-access-control-allow-origin","tag-ispconfig-cors","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/comments?post=833"}],"version-history":[{"count":2,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/833\/revisions"}],"predecessor-version":[{"id":835,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/833\/revisions\/835"}],"wp:attachment":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/media?parent=833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/categories?post=833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/tags?post=833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}