$.ajax ({function ( ) {$.ajax({function () { $.ajax () { function () {complete (); });});});
Solution:
<script>/** Take a few settimeout to do an example. * One second after output 1, then one second after output 2, then one second after output 3 * The original practice is a sentence nested down*/SetTimeout (function(){ //Output 1Console.log (1); SetTimeout (function() { //Output 2Console.log (2); SetTimeout (function() {Console.log (3); }, 1000); }, 1000); }, 1000); /** Now there is a better way to write, is to use the promise.js to simple*/ varAsny =function(text) {varPromise =NewPromise (function(Resolve, Reject) {SetTimeout (function() {console.log (text); Resolve (); }, 1000) }); returnpromise; } Asny ("1"). Then (function(){ returnAsny ("2"); }). Then (function () { returnAsny ("3"); }). Then (function() {Console.log ("Done"); }); </script>
How to fix too deep code nesting issues