JSFiddle - React, Tailwind, and code Playground
JavaScript
var toolbelt = {};
// REMOVE second argument 'dataSet', it is not appropriate here
toolbelt.getData = function(url, func){
var request = new XMLHttpRequest();
request.open('POST', url, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
var data = JSON.parse(request.responseText);
// DON'T access seoApp here:
//seoApp[dataSet] = data;
func(data);
} else {
// We reached our target server, but it returned an error
alert("The target server was reached but there was an error returned.")
}
}
request.onerror = function() {
// There was a connection error of some sort
alert('There was a connection error. try again later.')
};
request.send();
}
var seoApp = {};
// Start the interval ticker:
seoApp.interval = setInterval(function () {
console.log('still waiting...');
}, 6000);
// Define bodyCount function, which you reference later
seoApp.bodyCount = function (data) {
seoApp['siteData'] = data; // set it here!
clearInterval(seoApp.interval); // stop the interval ticker
};
seoApp.getSiteData = function(){
var URL = seoApp.WORKING_URL
var KEYWORDS = seoApp.KEYWORDS
// Remove the second argument, the bodyCount function will cover this.
toolbelt.getData('serve/app.php?url='+ URL + "&keywords=" + KEYWORDS, seoApp.bodyCount);
};