Note that there are some explanatory texts on larger screens.

plurals
  1. POGithub API and Access-Control-Allow-Origin
    primarykey
    data
    text
    <p>this probably is a simple (series of) question(s) but I can't wrap my head around it.</p> <p>I'm trying to access the github api from a web app hosted on my site. This is the code in a nutshell:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt;p { color:red; }&lt;/style&gt; &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function () { $.ajax( {url :'https://api.github.com/repos/janesconference/kievIIPlugins/commits', dataType: "json", cache: false, success: function (data, textStatus, jqXHR) { var lastCommitSha = data[0].sha; $("p").text("Last commit SHA: " + lastCommitSha); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;Ajax request not (yet) executed.&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>If I point my browser to this simple page uploaded <a href="http://dl.dropbox.com/u/6767816/ghapi.html" rel="noreferrer">on my dropbox account</a> everything is ok. If, instead, I point my browser to this simple page uploaded <a href="http://bitterspring.net/ghapi.html" rel="noreferrer">on my site</a>, I get the infamous <code>Access-Control-Allow-Origin</code> exception:</p> <pre><code>XMLHttpRequest cannot load https://api.github.com/repos/janesconference/kievIIPlugins/commits?_=1360060011783. Origin http://bitterspring.net is not allowed by Access-Control-Allow-Origin. </code></pre> <p>So, the questions:</p> <ul> <li>Why does it work on Dropbox?</li> <li>I understand that with CORS it would work even on the website. This is a matter of putting <code>Access-Control-Allow-Origin: *.github.com</code> on my Apache configuration or something like that. But, as quoted from en.wiki, </li> </ul> <blockquote> <p>However, this might not be appropriate for situations in which security is a concern</p> </blockquote> <ul> <li>Is there a way to do this without changing the Apache configuration? Probably, I can't touch the Apache conf of my hosting site, and there's always the security concern. What is the right way to do this?</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload