Making a synchronous DWR call
Posted on September 18th, 2008 in DWR, JavaScript | 9 Comments »
It took me about half an hour of Googling to find this, and I couldn’t readily find this in the DWR documentation. Hopefully this may save someone some time:
To make a DWR call synchronous (meaning browser-blocking) you must pass an object as one of the arguments of your DWR call with a property async set to false.
I needed this feature in project where a collection object sends out a call for more data if it didn’t have it:
... _getData: function(offset, limit){ var r; DWRcomponent.getComments(offset, limit,{ async: false, callback: function(s){ r = toJSON('(' + s + ')'); } }); return r; } ...

9 Responses
Did you run into any problems yet?
For us, sometimes the browser doesn’t block, which results in undefined being returned, since the variable r isn’t set yet.
This only seems to happen in certain cases, when you come back to the page using the back button or via a bookmark.
Very useful post. Saved me a lot of search time !!!!
More info:
http://directwebremoting.org/dwr/browser/engine/options.html
is that toJSON method from prototype?
That’s just a made up function where you can use your own. You can either just use eval in its place or the free library from json.org if you don’t trust the source your making the call from.
Really saved me a lot of time!! thanks so much!
Oh my god!!!
I wasted a full day on this issue!!! You’re a life saver!!
thanks!!
it works!
I spent a lot of time to fix a problem, but this solves my problem
The problem was that IE8 sometimes does not show the data, and when I make some ajax call synchronous it solves the problem :)
Thanks a lot