MeasurementTesting / static /API_Refresh_workerJS.js
Marthee's picture
Update static/API_Refresh_workerJS.js
457e395 verified
raw
history blame
2.63 kB
intervalBegin()
function intervalBegin(){
// minutes= min *60*1000
intervalAPI= setInterval( getRefreshAPIAjax ,1800000) // 30*60*1000 // every 30 min
}
function getRefreshAPIAjax(){
ajax("/refreshAPI")//, sectionData)
.then(function(data) {
self.postMessage(data); // Code depending on result
})
}
function ajax(url , sectionData) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
resolve(this.responseText);
};
xhr.onerror = reject;
// xhr.open('POST', url, true);
// xhr.send("sectionData=" + sectionData);
xhr.open('GET', url)//+'?sectionData=' + sectionData);
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();
// }
// })
// }