Making a synchronous DWR call
Posted on September 18th, 2008 in DWR, JavaScript |
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; } ...
One Response
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.