Fire function only on the intial load of profound app
Posted: Tue May 11, 2021 12:10 pm
Is there a way to call a js function only once when the page loads initially?
I have a function that is currently being called on my main screen onload field in visual designer.
This function makes an ajax request with a setTimeout of 6000 and then the function calls itself. This is to keep the data real time.
What i'm noticing is that when the main screen reloads, which is what happens when i click on something on the screen, a new sequence of timeouts is started. What i mean is that the stack is backloaded with all of these requests and i'm making my ajax call every second. This is not the desired behavior.
I tried doing something like but this breaks profound, meaning i cannot even start a new session. So what I would like to do is call a function one time when the app loads
I have a function that is currently being called on my main screen onload field in visual designer.
This function makes an ajax request with a setTimeout of 6000 and then the function calls itself. This is to keep the data real time.
Code: Select all
function makeRequest(){
var program = pui.get('PROGRAM');
if(program !== 'CL5001RP'){
return;
}
var url = pui.get("envURL");
$.ajax({
url: url,
method: "get",
dataType: "html"
})
.done(function(resp){
var json = JSON.parse(resp);
if(json !=''){
pui.set("data1",json.data.data1);
}
setTimeout(makeRequest, 6000);
})
}
I tried doing something like
Code: Select all
window.onload = function(){makeRequest()}