javascript - The loading order of Js code and ajax request of Jquery in the Dom -
function f(){ $.post('1.php',{},function(){window.location.href="../../2.php";}); }
when click button,excute function f.the code above can run correctly , achieve wanted function.but when code changes follow format:
function f(){ $.post('1.php',{},function(){}); window.location.href="../../2.php"; }
the ajax request not work.i know has javascript load order,but want make clear in deep level.it nice of me , explain in detail.thank you!
when have
$.post('1.php',{},function(){}); window.location.href="../../2.php";
the second line executed first 1 has been executed. first statement launches ajax request, doesn't block until browser has sent whole request server.
as second line replaces page, stops script , tells browser can stop being doing page, querying server.
the solution have in first code :
$.post('1.php',{},function(){window.location.href="../../2.php";});
the window.location
change done when browser has received answer.
Comments
Post a Comment