From my understanding of what I have read thus far, the below piece of code hosted on a domain other than "jsonplaceholder.typicode.com" must fail, but it does not. Why? It is a AJAX Cross Domain request.
<!DOCTYPE html>
<html>
<body>
<div id="demo"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadDoc()">Change Content</button>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "http://jsonplaceholder.typicode.com/posts/1", true);
xhttp.send();
}
</script>
</body>
</html>
But this works fine, without using any tricks like JSONP. Why?