Generally, the method to obtain the value of the DWR method on the page is
Function Test (){
Dwrtest. Hello (function (data) {alert (data )})
}
It is difficult to return this value for your JavaScript test method. The DWR method returns the value after execution by calling the specified function. We often do this.
Function Test (){
VaR result;
Dwrtest. Hello (function (data) {result = data })
Return result;
}
The aboveCodeThe returned value is "undefined ".
Dwrtest. Hello (function (data) {result = data })
In this sentence, the "function (data) {result = data}" method is passed to dwrtest. A parameter of Hello is called after the hello method is executed. Therefore, if it is not executed in test (), an uninitialized "result" is returned ".
In fact, this is an asynchronous processing process, andJavascriptSynchronization is performed by default.
We just need to change the above Code:
Code
Function Test (){
VaR Result;
Dwrengine. setasync ( False );
Dwrtest. Hello ( Function (Data) {result = Data })
Dwrengine. setasync ( True );
Return Result;
}
In this way, when Javascript is executed, it will wait until "dwrtest. Hello" is executed and then execute the following statement. Then we can directly obtain the returned value.