MeasurementTesting / static /API_Refresh_workerJS.js
Marthee's picture
Upload API_Refresh_workerJS.js
7fd2614 verified
raw
history blame
2.48 kB
getRefreshAPIAjax()
intervalBegin()
function intervalBegin(){
// minutes= min *60*1000
intervalAPI= setInterval( getRefreshAPIAjax ,300000) // 60*60*1000
}
function getRefreshAPIAjax(){
ajax("/refreshAPI")
.then(function(data) {
var data1=JSON.parse(data);
self.postMessage(data); // Code depending on result
})
}
function ajax(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
resolve(this.responseText);
};
xhr.onerror = reject;
xhr.open('GET', url);
xhr.send();
});
}
function appendtotables(data){
ajax('/refreshAPIAppendNewTables?keyword=' + data, true)
.then(function(data) {
console.log('ok')
// self.postMessage('appended'); // Code depending on result
});
}
// $.ajax({
// type: "POST",
// url: '/refreshAPIAppendNewTables',
// // set content type header to use Flask response.get_json()
// contentType: "application/json",
// // convert data/object to JSON to send
// data: JSON.stringify({value:data[1]}),
// // expect JSON data in return (e.g. Flask jsonify)
// dataType: "json",
// // handle response
// success: function(response) {
// self.addEventListener('message', function(e) {
// self.postMessage('heeeeyyyy');
// }, false);
// if (data[1].toString()==='projectsection')
// {
// displayprjnames();
// displayprojsections();
// }
// if (data[1].toString()==='project')
// displayprjnames();
// if (data[1].toString()==='part')
// displayprojparts();
// if (data[1].toString()==='section')
// displayprojsections();
// if (data[1].toString()==='projectpart')
// {
// displayprjnames();
// displayprojparts();
// }
// if (data[1].toString()==='partsection')
// {
// displayprojparts();
// displayprojsections();
// }
// },
// error: function(err) {
// PopupElement.textContent='Error occured. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
// ShowPopUp();
// }
// })
// }