Modern Browsers don't allow you to send requests to another website that doesn't have the Cross-Origin Header set.
My specific problem:
I wanted to write a browser-based viewer of someone's REST API, but I couldn't get them via a Javascript request, only with non-browser requests.
PHP doesn't care about Cross Origin requests and is easy to setup.
Create a small "PHP proxy" to get the resource and forward it to your browser's javascript request.
Example PHP code (filename: t.php):
<?php $json = file_get_contents('https://example.com/api/v1/status?key=XXX&server='.$_GET['id']); $arr = json_decode($json, true); //Accessible Array from JSON answer echo $arr['response']['serverstatus']; ?>
return $.ajax({ type: "GET", url: "https://myserver.com/t.php?id="+id }).done(function(data) { document.body.innerHTML += data+"<br>"; });