I am trying to bypass the error:
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
By including external javascript file containing html data. So what I want to achieve is, to load the html content when a side menu is clicked. In the process, I want the earlier data to be replaced by the new one so that I can replace the old content with the new one. Below is the main part of the code.
function change_current_doc(clicked_file, doc_src) {
//Change current JavasScript file containing data with the new one.
var prev_doc_src = doc_src;
var prev_doc = doc;
doc_src = html_file.doc_path + '/' + clicked_file.split('.')[0] + '.json';
var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
if (scripts[i].src.indexOf(prev_doc_src) > 0) {
scripts[i].remove();
var doc_script = document.createElement('script');
doc_script.setAttribute('src', doc_src);
document.head.appendChild(doc_script);
break;
}
}
}
$(document).ready(function () {
$('#st_side_menu').jstree({
"plugins": [
"types",
"unique",
"wholerow",
"changed"
],
"types": {
"default": {
"icon": "images/book.png",
"select_node" : function(e) {
this.toggle_node(e);
return false;
}
},
"moveType": {
"icon": "glyphicon glyphicon-transfer"
}
}
}).on('changed.jstree', function (NODE, REF_NODE) {
//Loads the new file on button click however, it is out of sync, it
//requires to be clicked two times.
var clicked_file = REF_NODE.node.a_attr.href;
if (clicked_file.length < 5){
return
}
console.log(clicked_file);
// Actual changing happens here.
change_current_doc(clicked_file, doc_src);
// data is set here.
$('#doc_container').html(doc[0]);
})
});
My json data in js file.
var doc = ["<!DOCTYPE HTML>\n<html>\n<head>\n <meta content=\"text/html;...];
What I am looking for is, if there is any way to reset the old doc global variable and set the new one without clicking twice.
I didn't need to go through all this long way if I had an option to access the web application from server. I have no option to get away with this as users will access it from a folder.