Last active
November 9, 2015 11:45
-
-
Save b-yao/23fc61b0505f0ffb8165 to your computer and use it in GitHub Desktop.
Two ways to access service layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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