假定我们有个类似这样的Java方法
public class Remote {
public String getData(int index) { ... }
}
在页面中调用这个方法,如下:
<script type="text/javascript"
src="[WEBAPP]/dwr/interface/Remote.js"> </script>
<script type="text/javascript"
src="[WEBAPP]/dwr/engine.js"> </script>
...
function handleGetData(str) {
alert(str);
}
Remote.getData(42, handleGetData);
其中函数handleGetData()就是回调函数,服务器的方法getData()获取到数据后回调上层的js函数以显示结果。