I'm trying to let the user open a tab to keep letting him use the system while the current tab is making some request to the server.
so I'm opening a new tab and trying to use $(window).load() or $(window.document).ready() to click on some item when the elements are ready. When testing it with a large server request, the window is only loaded when the ajax request returns with the result and finishes the success function even though it should be async.
Would love some ideas why it is happening.
g_SearchHandler.SearchPleaseWait(true); is calling covering the screen with a waiting gif and calling displayNewTab() that opens a new tab.
code to open new tab:
displayInNewTab: function(){
try {
var w = window.open(href = "/prod/php/home.php");
var loadingFunc = function(){
var devices = w.document.querySelector(`.sidebar-segment[data-segment-name="DEVICES"]`);
var selDevice = getSelectedDeviceTreeData();
if(!selDevice){
return;
}
var selDeviceObj = w.document.getElementById(selDevice.name);
//when the window is loaded keep trying until elements are available for clicking.
if(devices && selDeviceObj){
devices.click()
w.ClickOnItem(selDevice.name, false, true)
}else{
setTimeout(loadingFunc,1000);
}
}
$(w.document).ready(loadingFunc);
}catch (e){
console.error(e)
}
}
g_SearchHandler.SearchPleaseWait(true); ajax request:
$.ajax({
type : "POST",
dataType : "json",
url : "commands.php",
data : params,
success : function(objJSON)
{
DisplayResults(objJSON);
g_SearchHandler.SearchPleaseWait(false);
}
});