ajax - JavaScript call stack -
i'm new web development , have been reading on ajax can update map live new data. i'm reading ibm article on comet. provide implementation apache tomcat.
article : http://www.ibm.com/developerworks/web/library/wa-cometjava/#resources
the javascript code provide follows..
<script type="text/javascript"> function go(){ var url = "http://localhost:8484/weatherserver/weather" var request = new xmlhttprequest(); request.open("get", url, true); request.setrequestheader("content-type","application/x-javascript;"); request.onreadystatechange = function() { if (request.readystate == 4) { if (request.status == 200){ if (request.responsetext) { document.getelementbyid("forecasts").innerhtml = request.responsetext; } } go(); } }; request.send(null); } </script> </head> <body> <h1>rapid fire weather</h1> <input type="button" onclick="go()" value="go!"></input> <div id="forecasts"></div> </body>
i understand have few questions.
1) request.send() spawn new thread? 2) recursive call go() cause stack overflow?
a new thread created when request.send()
unless specify explicitly not in open-method.
the call go
never cause stackoverflow-exception. because called in callback , call stack reset when data returns. may recursive function, it's not. although it's defined inside go-function, execution-context different.
Comments
Post a Comment