on 02-06-2015 1:11 PM
I have the following fragment of code:
<script>
someGrid = new dhtmlXGridObject('someGridContainer');
// additional someGrid settings...
someGrid.loadXML("url", function () {
console.log('inside loadXML');
});
console.log('after loadXML');
</script>
If I run it on my local PC, I will receive:
inside loadXML
after loadXML
But when executing this within MII, I will receive:
after loadXML
inside loadXML
Why?
It looks like your loadXML method is executing asynchronously, getting whatever is located at the url you are passing, and then calling your anonymous function when complete. This is probably just happening faster on your local pc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I supposed it so... but I'm receiving the same order of messages for this case too:
<script>
someGrid = new dhtmlXGridObject('someGridContainer');
// additional someGrid settings...
someGrid.loadXML("url", function () {
console.log('inside loadXML');
});
for ( var i = 0 ; i < 1000000 ; i++) { i += 1; i -= 1;}
for ( var i = 0 ; i < 1000000 ; i++) { i += 1; i -= 1;}
for ( var i = 0 ; i < 1000000 ; i++) { i += 1; i -= 1;}
for ( var i = 0 ; i < 1000000 ; i++) { i += 1; i -= 1;}
for ( var i = 0 ; i < 1000000 ; i++) { i += 1; i -= 1;}
console.log('after loadXML');
</script>
Hi Swaroop,
unfortunately "load()" functions are only asynchronous..
but I still don't understand this story... I had to wait at least 3 seconds until the five dummy for-loops finished their execution, and then both of the log-messages appeared immediately in the following order:
after loadXML
inside loadXML
Isn't there any setting in MII that makes this behavior?
This behavior has nothing to do with MII. This is all happening on the browser/client and is normal behavior. Even tho the call to go get the document from MII is async, Javascript is single threaded. The javascript engine asks the browser to go get the doc from the url and let it know when its done. The engine then continues doing whatever else it needs to do. When the browser is done getting the doc it lets the engine know. When the engine gets a chance and its not busy it will get to it and execute your callback function. So your browser may have gone and gotten the document but your javascript engine is still busy looping or whatever so your callback has to wait. If you want your 'after Load' to always execute after your 'inside load' you have to make your load call synchronous, or put it in your callback function, or use a promise.
may I have a last question? consider the following code:
function f () {
someGrid = new dhtmlXGridObject('someGridContainer');
// additional someGrid settings...
someGrid.loadXML("url", function () {
console.log('inside loadXML');
});
console.log('after loadXML');
}
Function f() is called and loadXML() function is being executed inside it... May we leave function f() during the execution of loadXML() ?
Try below:
If you want to wait until all ajax requests are finished in your document, no matter how many of them exists, just use $.ajaxStop
event this way:
$(document).ajaxStop(function () { // 0 === $.active });
Reference: Wait until all jQuery Ajax requests are done? - Stack Overflow
Hope this helps.
Regards,
Swaroop
Hi Tibor,
I can suggest a workaround of applying some delay or time lag in order to make the function execute after certain time.
Let me know if this works.
-Snehal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
6 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.