开发者

add parameter to function in c# and js

i need to give parameter to a function, i'm not sure how to do so i need to add a parameter in my read function so i can use the same function several times, i added a parameter called val and tested if its equal to the value i need to call a function, now my problem is that i don't know how to add that parameter in the read function in my script (objhandler.read('one') ?? )

in my .js file i have this :

 var objHandler = new Interact(); // create an object the the handler class in javascript file. using this object, we can access the methods in the handler class.

function SayRead() {
    try {
        objHandler.Read(function (serverResponse) {
            if (serverResponse.error == null) {   
                var result = serverResponse.result;
                if (result.length > 2) {
                    SessionStore.loadData(Ext.decode(result));
                }
            }
            else {
                alert(serverResponse.error.message);
            }
        }//eo serverResponse
        ); 
    } //eo try
    catch (e) {
        alert(e.message);
    }
}

SayRead();

in my .ashx.cs file i have :

public class Interact : JsonRpcHandler
{
    [JsonRpcMethod()]
    public string Read(string val)
    {
        // Make calls to DB or your custom assembly in project and return the result in JSON format. This part is making custom assembly calls.

        clsDBInteract objDBInteract = new clsDBInteract();
 开发者_运维百科       string result;
        try
        {
            if (val == "one")
            result = objDBInteract.FetchSessionsJSON();
            //if (val == "two") result = objDBInteract.FetchJobsJSON();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return result;
    }
}

P.S: i use jayrock library

thanks.


I think more details would be helpful. I assume you are using a library / toolkit like jayrock. Please let us know.

You might want to try

objHandler.Read('one', function (serverResponse) {

This is AFAIK the way Jayrock would create the function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜