This code is started in a browser console. Later it will be used as a bookmarklet.
(function(doc) {
function doStuff() {
/***************/
/* } Load data */
/***************/
function successfullyLoadData(data){
debugger;
}
function loadData(){
debugger;
var data;
jQuery.ajax({
dataType: "json",
url: "https://example.com/wp-content/plugins/n-bookmarklet/static/data/data.json",
data: data,
success: successfullyLoadData
});
}
loadData();
/***************/
/* } Load data */
/***************/
....
/**************************/
/* Load JavaScript libs { */
/**************************/
if (typeof jQuery == 'undefined') {
var script_jQuery = document.createElement('script');
script_jQuery.src = 'https://example.com/wp-content/themes/nonverbis_reboot_academic/static/js/jquery-3.6.1.min-1.js';
/* call doStuff() after jQuery.js loads */
script_jQuery.onload = loadEasyTimer;
doc.body.appendChild(script_jQuery);
console.log('script_jQuery appended to body');
} else {
console.log('jQuery already included ...');
/* initialize your code using existing version */
loadEasyTimer();
}
function loadEasyTimer(){
if (typeof easytimer == 'undefined') {
var script_easytimer = document.createElement('script');
script_easytimer.src = 'https://example.com/wp-content/plugins/n-ege-timer/static/js/easytimer.min-1.js';
/* call doStuff() after jQuery.js loads */
script_easytimer.onload = doStuff;
doc.body.appendChild(script_easytimer);
console.log('script_easytimer appended to body');
} else {
console.log('script_easytimer already included ...');
/* initialize your code using existing version */
doStuff();
}
}
/**************************/
/* } Load JavaScript libs */
/**************************/
})(document)
Problem:
What we have here:
- jQuery and Easytimer are loaded.
- data.json is not loaded. No 'Access-Control-Allow-Origin'.
Well, json is just data. This protection is mostly about JavaScript. But as we can see JavaScript is executed.
I can add the necessary header to suppress this error.
But I want to understand why this error has something to do with .json and doesn't care about .js?