Skip to content

Instantly share code, notes, and snippets.

@b-yao
Last active November 9, 2015 11:45
Show Gist options
  • Save b-yao/23fc61b0505f0ffb8165 to your computer and use it in GitHub Desktop.
Save b-yao/23fc61b0505f0ffb8165 to your computer and use it in GitHub Desktop.
Two ways to access service layer
<!-- by using mootools -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mootools/1.5.2/mootools-core-compat.js"></script>
<script>
var Call = new Request({
url: 'http://sl1.hackathon.studyportals.xyz/data/students/all/1337/'
});
Call.get();
</script>
<!-- self-contained -->
<script>
var createCORSRequest = function(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Most browsers.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// IE8 & IE9
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
};
var url = 'http://sl1.hackathon.studyportals.xyz/data/students/all/1337/';
var method = 'GET';
var xhr = createCORSRequest(method, url);
xhr.onload = function() {
// Success code goes here.
};
xhr.onerror = function() {
// Error code goes here.
};
xhr.send();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment