这可能是一个简单的(系列)问题,但我无法绕过它.
我正在尝试从我网站上托管的网络应用程序访问github api.这是代码简而言之:
<!DOCTYPE html>
<html>
<head>
<style>p { color:red; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(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);
}
});
});
</script>
</head>
<body>
<p>Ajax request not (yet) executed.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果我将浏览器指向我在Dropbox帐户上上传的这个简单页面,一切正常.相反,如果我将浏览器指向我网站上传的这个简单页面,我会得到臭名昭着的Access-Control-Allow-Origin例外:
XMLHttpRequest cannot load https://api.github.com/repos/janesconference/kievIIPlugins/commits?_=1360060011783. Origin http://bitterspring.net is not allowed by Access-Control-Allow-Origin.
Run Code Online (Sandbox Code Playgroud)
所以,问题:
Access-Control-Allow-Origin: *.github.com我的Apache配置或类似的事情.但是,如引自en.wiki,但是,这可能不适合担心安全问题的情况 …