在javascript中使用回调将参数传递给dwr调用函数

时间:2022-02-18 16:02:43

I have a DWR bean class which i can reference through JavaScript. I also have a function called getWritableContactSQL in that class as

我有一个DWR bean类,我可以通过JavaScript引用它。我在该类中也有一个名为getWritableContactSQL的函数

public static string getWritableContactSQL(String, String, String){...}

Now I have the 3 parameters available to be in the JavaScript code. I want to call this function with those parameters and want to use the output of this function into another JavaScript function as :

现在我有3个参数可用于JavaScript代码。我想用这些参数调用这个函数,并希望将此函数的输出用于另一个JavaScript函数:

function slqDone(data){...}

If the getWritableContactSQL function did not have any arguments, I would have called it like:

如果getWritableContactSQL函数没有任何参数,我会调用它:

getWritableContactSQL(sqlDone);

But I have arguments and don't know how to do this. I have practically no knowledge of AJAX.

但我有论据,不知道该怎么做。我几乎不了解AJAX。

1 个解决方案

#1


1  

First from the javascript function , java method getWritableContactSQL(a,b,c) will be called.

首先从javascript函数中调用java方法getWritableContactSQL(a,b,c)。

    DwrUtil.getWritableContactSQL(a,b,c,getWritableContactCallBack);

    getWritableContactCallBack is the callback function.  

After the request is done some data will be returned.This will be returned in the callback function.

请求完成后,将返回一些数据。这将在回调函数中返回。

    function getWritableContactCallBack(data)
    {
       dwr.util.setValue("divId", "got data", {
                          escapeHtml : false
                        });
    }

#1


1  

First from the javascript function , java method getWritableContactSQL(a,b,c) will be called.

首先从javascript函数中调用java方法getWritableContactSQL(a,b,c)。

    DwrUtil.getWritableContactSQL(a,b,c,getWritableContactCallBack);

    getWritableContactCallBack is the callback function.  

After the request is done some data will be returned.This will be returned in the callback function.

请求完成后,将返回一些数据。这将在回调函数中返回。

    function getWritableContactCallBack(data)
    {
       dwr.util.setValue("divId", "got data", {
                          escapeHtml : false
                        });
    }