I need to make a div that covers my entire screen be displayed before an sync ajax call.
But it seems that absolutely nothing I try to do causes the DOM to be modified to show this div before the ajax call. The screen gets "frozen" and the div is showed only after the ajax call is executed.
I have already tried "thousands" of approaches but nothing seems to make ajax run only after the DOM is modified (shows the div).
HTML
[...]
<body>
<div id="loadingDiv" style="display: none; width: 100%; height: 100%; background-color: #004000; position: absolute; z-index:10000;"></div>
[...]
javascript
[...]
$("#loadingDiv").css("display", "block");
var ajaxOp;
$.ajax({
type: someType,
url: someUrl,
data: someData,
dataType: someDataType,
async: false,
success: function (someArg) {
ajaxOp = someArg;
},
error: function (someArg0, someArg1, someArg2) {
// do something
}
});
return ajaxOp;
[...]
NOTE I: I'm using JQuery.
NOTE II: "ajaxOp" can not be "undefined".
UPDATE: In the hope that it helps the understanding and at the request of @Felipe Dutra Ferreira I put some more explanations about the issue in the update below...
THE REAL CASE: I have an application with several legacy codes that consume a libray js with a function that, in turn, makes ajax calls (let's call it "certainfunction"). We are trying to update this application so that it displays a "loading screen" during ajax calls (not just "lock" the UI during these calls). So the simplest way to handle this problem is display the "loading screen" just after the calls to "certainfunction" and before it runs the ajax calls. Note also that "certainfunction" returns the output from the ajax call and this output will be "undefined" once this call is not executed synchronously, that is, the code can only continue after this ajax call has an output.