Skip to content

Instantly share code, notes, and snippets.

@sixtyfive
Last active August 23, 2017 19:25
Show Gist options
  • Save sixtyfive/19ec4d8f69c824cb0f27eba76e28d782 to your computer and use it in GitHub Desktop.
Save sixtyfive/19ec4d8f69c824cb0f27eba76e28d782 to your computer and use it in GitHub Desktop.
JS scope question
// Taken from https://stackoverflow.com/questions/9838812/how-can-i-open-a-json-file-in-javascript-without-jquery
function loadJSON(path, success, error) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
if (success) {
success(JSON.parse(xhr.responseText));
}
} else {
if (error) {
error(xhr);
}
}
}
};
xhr.open('GET', path, true);
xhr.send();
}
(function() {
tinymce.create('tinymce.plugins.InsertExercise', {
InsertExercise: function(ed, url) {
...
function showDialog() {
...
loadJSON(exercises_url,
function(data) {
/* I need to access "ed" here! Possible somehow? */
},
function(xhr) {console.error(xhr);}
);
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment