I read that the main idea behind the browser security policy is that you can't retrieve data from a domain that is different from the domain the page itself was served from. But I don't understand why I can do this then?
<!doctype html>
<html>
<head>
<title>Template</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<script src="jscript.js"></script>
</head>
<body>
</body>
</html>
window.onload = function() {
var request = new XMLHttpRequest();
var url = "http://mbigras.github.io/geolocation/data.json";
request.open("GET", url);
request.onload = function() {
if (request.status == 200) {
var object2 = JSON.parse(request.responseText);
alert(object2.name + ", age " + object2.age);
}
}
request.send(null);
};
Because isn't the the page being served from my computer at home (index.html on my local machine) while I'm using XMLHttpRequest to request json data from github? Or am I misunderstanding something here?