This is an odd problem. I have a client object that I am building up using Crockford-esque public/private members:
var client = function() {
var that, remote_
You can do a loop (optionally with a timeout) to wait for the async to finish. Warning, this will (as requested) block all other functionality and may cause the browser to freeze if it takes much too long. However, you really should figure out an asynchronous way to do what you need instead of blocking like this.
var syncRequest = function(options) {
var is_finished = false;
var result;
var finished_callback = function(response) {
is_finished = true;
result = response.result;
}
ajax_request(options, finished_callback);
// timeout in 30 seconds
var timeout = (new Date()).getTime() + 30000;
while ( !is_finished ) {
if ( (new Date()).getTime() >= timeout ) {
alert('Request timed out');
}
// do nothing, just block and wait for the request to finish
}
return result;
}