Given the fact that Javascript is a single-threaded language, what would be the sequence of execution in the following code in ExtJs?
FuncA();
Ext.Ajax.request({
url: 'ajax.php',
params: {
id: 1
},
success: function(response){
FuncB();
}
});
FuncC();
FuncD();
Here would the sequence of execution of functions be A-C-D-B?
Or
Is it ever possible that FuncB() gets called prior to FuncC() or FuncD()? If yes, then in which conditions?
Thanks in advance for any help.
The order will always be A-C-D-B unless the ajax request is synchronous, but it’s not really recommended to use that since it causes the UI to hang.
For example, try this (in Chrome, preferably)
You will see that even though it takes around 1s to run the code, the ajax request always fires last, even though the request itself only takes around 7ms (it’s a local box). Then try it again by commenting out the calls to f1/f2.