{"id":590,"date":"2012-04-28T13:09:53","date_gmt":"2012-04-28T13:09:53","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=590"},"modified":"2012-04-28T13:09:53","modified_gmt":"2012-04-28T13:09:53","slug":"subdomain-xmlhttprequest-origin-allowed","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/subdomain-xmlhttprequest-origin-allowed\/","title":{"rendered":"Subdomain XMLHttpRequest &#8211; Origin is not allowed"},"content":{"rendered":"<p>If you&#39;ve tried using AJAX via your browsers XMLHttpRequest object to access data from another domain, you are greeted with an error similar to <em>XMLHttpRequest cannot load &#8211; Origin is not allowed by Access-Control-Allow-Origin<\/em>.<\/p>\n<p>In a nutshell, this means the JavaScript is restricting your AJAX calls to within your domain, or at least that&#39;s what the docs say. What they often don&#39;t say is that this same rule applies across subdomains within your domain.<\/p>\n<p>This is of particular annoyance if you are trying to develop a mobile version of your website, which leverages parts of your primary site. The gurus out there tell you to use <a href=\"http:\/\/en.wikipedia.org\/wiki\/JSONP\">JSONP<\/a>, which works just fine.<\/p>\n<p>But, if you&#39;re like me, you&#39;ve grown particular fond of the concise little jQuery $.ajax() function, and hate to give it up!<\/p>\n<p>Fortunately, if your subdomains are on the same server, you can create a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Symbolic_link\">symbolic link<\/a> (Linux) to the directory, or files you need to access within your primary site, i.e.<\/p>\n<p><code>ln -s \/path\/to\/my\/primary\/site\/functions functions<br \/>\n\t<\/code><\/p>\n<p>Now, from your mobile site, you can access the functions from your primary site, simply by referencing the symbolic link. The browser has no idea what&#39;s going on server-side, so you&#39;re back in the AJAX game!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#39;ve tried using AJAX via your browsers XMLHttpRequest object to access data from another domain, you are greeted with an error similar to XMLHttpRequest&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[5,123],"tags":[170],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/590"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=590"}],"version-history":[{"count":1,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/590\/revisions"}],"predecessor-version":[{"id":591,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/590\/revisions\/591"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}