javascript - Why are ajax calls to two page methods being executed synchronously? -
i have 2 script tags on page, each containing document.ready(), , each of them making ajax call page method.
first 1 loads values select list. second 1 loads tree dom.
<script> $(document).ready(function() { $.ajax({ url: 'pagemethods.aspx/gettop50', async: true, success: function(data) { //loads values select list } //rest of stuff... }); }) </script> <script> $(document).ready(function() { $.ajax({ url: 'default.aspx/gettree', async: true, success: function(data) { // loads tree dom } //rest of stuff... }); }) </script>
why gettree
page method keep executing after success callback of gettop50
? set breakpoint gettree method serverside, , hit after select list loaded.
the client start both ajax calls 1 after other both "in-flight" @ same time. server 1 complete first , depend upon how server configured (will process multiple requests @ once) , depend upon each request doing.
if server handles 1 request @ time or if blocks on shared resource such database, return first request received before returning second request result - though that's option, not guaranteed option. example, if first request pretty takes longer process second , aren't both contending same shared resource, second request might finish first , return results first.
it possible requests return in random order such 1 return first , other return first. said earlier, depends upon how server processes each request , 1 finishes first.
also, keep in mind client-side js single threaded when sitting @ client-side js breakpoint somewhere, other js cannot run until current js thread of execution has finished. behavior in breakpoints on server-side, depends upon server execution environment , how works during breakpoint.
if want debug timing-related things, breakpoint not reliable way test things because hitting breakpoint can affect behavior. instead, should use logging accurate timestamps study exact sequence of events.
Comments
Post a Comment