I have a jquery javascript to update to page every x minutes/seconds. I want to define this update interval in a separate json-config file so that the project can be easily configurated. I have a javascript named ConfigReader which has a method to read this config-file. I want know to load this ConfigReader to my jQuery javascript with 'require' but because the jQuery is on Clientside it does not know require.
How can I import my ConfigReader to my jQuery javascript file?
Here is the jQuery file:
var ConfigReader = require('../libs/ConfigReader');
var update = function() {
var divs = $('div[id^="data-"]')
for (var i = 0; i < divs.length; i++) {
var id = divs[i].id;
var dataType = id.split('-')[1];
var cacheId = id.split('-')[2];
$.ajax({
type: "GET",
url: '/' + dataType + 'View?cacheId=' + cacheId,
context: id,
success: function(data) {
console.log("id=" + id + " this=" + this);
$("#" + this.replace(/\./g, '\\\.')).html(data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(this + "View", jqXHR, textStatus, errorThrown);
}
});
}
}
var configReader = new ConfigReader();
var configUpdate;
var configuration = configReader.getConfigutation();
for(var i = 0; i < configuration.length; i++){
var current = configuration[i];
switch(current["name"]){
case "update":
configUpdate = parseInt(current["interval"]);
break;
}
}
$(document).ready(function() {
update();
window.setInterval(update, configUpdate);
});