A solution to using Thread.Sleep() inside JavaScript.
// do something here
$.ajax({
url: "http://sleepy.apphb.com/sleep/1000", // sleep for 1000ms on the server
async: false // execute this request synchronously
});
// continue doing something here
Or include jquery.sleepy.js
and simply call $.sleep(1000);
:
<script src="http://sleepy.apphb.com/scripts/jquery.sleepy.js"></script>
// do something here
$.sleep(1000);
// continue doing something here
// sleep for the default amount of time, i.e. 1000ms
$.sleep();
// call the provided callback function when done sleeping
$.sleep(2000, function () {
alert("Done sleeping.");
});
// call the provided callback function with the server response data
// currently there's one property, slept, which contains the time slept
$.sleep(2000, function (data) {
alert("Slept for " + data.slept + "ms.");
});