Skip to content

Instantly share code, notes, and snippets.

@peter-hank
Created February 9, 2017 14:25
Show Gist options
  • Save peter-hank/d960a0b2aa9557a09d1f34eb8a4c0aa8 to your computer and use it in GitHub Desktop.
Save peter-hank/d960a0b2aa9557a09d1f34eb8a4c0aa8 to your computer and use it in GitHub Desktop.
Sync JSON loading
<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