Created
February 9, 2017 14:25
-
-
Save peter-hank/d960a0b2aa9557a09d1f34eb8a4c0aa8 to your computer and use it in GitHub Desktop.
Sync JSON loading
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
<html> | |
<head> | |
<script> | |
function loadTextFileAjaxSync(filePath, mimeType) { | |
var xmlhttp=new XMLHttpRequest(); | |
xmlhttp.open("GET",filePath,false); | |
if (mimeType != null) { | |
if (xmlhttp.overrideMimeType) { | |
xmlhttp.overrideMimeType(mimeType); | |
} | |
} | |
xmlhttp.send(); | |
if (xmlhttp.status==200) | |
{ | |
return xmlhttp.responseText; | |
} | |
else { | |
// TODO Throw exception | |
return null; | |
} | |
} | |
var application_config_json = loadTextFileAjaxSync('http://petstore.swagger.io/v2/swagger.json', 'application/json'); | |
console.log(application_config_json); | |
var application_config = JSON.parse(application_config_json); | |
</script> | |
</head> | |
<body></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment