Skip to content

Instantly share code, notes, and snippets.

@arruw
Last active October 28, 2021 03:15
Show Gist options
  • Save arruw/ad60c6dc7efaeed7dc9a9a729efcf566 to your computer and use it in GitHub Desktop.
Save arruw/ad60c6dc7efaeed7dc9a9a729efcf566 to your computer and use it in GitHub Desktop.
Ajax over CORS proxy example - https://goo.gl/nP6eRV
{
"message": "Hello World!"
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello</title>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</head>
<body>
<div id="message">Loading...</div>
<script>
(function() {
$.ajaxSetup({
beforeSend: function(jqxhr, settings) {
// Proxy all ajax requests over https://crossorigin.me/
settings.url = 'https://crossorigin.me/' + settings.url;
}
});
$(function() {
var url = 'https://gist.githubusercontent.com/matjazmav/ad60c6dc7efaeed7dc9a9a729efcf566/raw/5b6a6f942ae9260333f1462dc63b89919b24b8c5/data.json';
$.get(url, function(res) {
console.log(res);
$('#message').text(res.message);
}, 'json');
});
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment