如何在客户端(JavaScript)上使用服务器端(VB.NET)的返回值?

如何在客户端(JavaScript)上使用服务器端(VB.NET)的返回值?,javascript,vb.net,pagemethods,Javascript,Vb.net,Pagemethods,是否可以使用PageMethods从客户端调用服务器端的函数,并在JavaScript中访问该函数的返回值?下面是一个例子: 客户端: function onBlur(){ //this function is called when you click away from a textbox PageMethods.SomeServerSideFunction(params, onSuccess, onFailure); } function onSuccess(){ //d

是否可以使用
PageMethods
从客户端调用服务器端的函数,并在JavaScript中访问该函数的返回值?下面是一个例子:

客户端:

function onBlur(){ //this function is called when you click away from a textbox
    PageMethods.SomeServerSideFunction(params, onSuccess, onFailure);
}

function onSuccess(){
    //do something on success
    //I want to be able to print out the server side function's return value here
     alert(PageMethods.DoesItWork(params)) //this is what I've tried, but it doesn't work 
}

function onFailure(){
    //do something on failure
}
<System.Web.Services.WebMethod()>
Public Shared Function DoesItWork(params As String) As Boolean
    'logic to determine a return value
     Dim RetVal as Boolean
     Return RetVal 'I want to be able to use this return value on the client side
End Function
服务器端:

function onBlur(){ //this function is called when you click away from a textbox
    PageMethods.SomeServerSideFunction(params, onSuccess, onFailure);
}

function onSuccess(){
    //do something on success
    //I want to be able to print out the server side function's return value here
     alert(PageMethods.DoesItWork(params)) //this is what I've tried, but it doesn't work 
}

function onFailure(){
    //do something on failure
}
<System.Web.Services.WebMethod()>
Public Shared Function DoesItWork(params As String) As Boolean
    'logic to determine a return value
     Dim RetVal as Boolean
     Return RetVal 'I want to be able to use this return value on the client side
End Function

公共共享函数DoesItWork(参数为字符串)为布尔值
'确定返回值的逻辑
Dim RetVal作为布尔值
Return RetVal'我希望能够在客户端使用此返回值
端函数

简单地说,我只需要能够在客户端访问服务器端函数的返回值。提前谢谢

从在线教程中盗取,但基本上你是这样做的:

[System.Web.Services.WebMethod]
public static string ToUpper(string data) {
  return data.ToUpper();
}
--