如何从jquery到C#类代码获取返回值

如何从jquery到C#类代码获取返回值,c#,jquery,asp.net,C#,Jquery,Asp.net,我有一门C#的课。我想让它用返回值从C#method调用jquery方法 我有下面的C级 public class test { public void get() { //here the code how to call jquery method with retun values } } <script type="text/javascript"> function displayservices() { return "hello"; } &

我有一门C#的课。我想让它用返回值从C#method调用jquery方法

我有下面的C级

public class test
{
public void get()
{
//here the code how to call jquery method with retun values
}
}
<script type="text/javascript">
function displayservices() {

return "hello";
        }

    </script>
我的jquery方法如下

public class test
{
public void get()
{
//here the code how to call jquery method with retun values
}
}
<script type="text/javascript">
function displayservices() {

return "hello";
        }

    </script>

函数displayservices(){
回复“你好”;
}

客户端即浏览器上的Javascript函数,无法将值返回到服务器端函数。您需要通过ajax调用服务器来传递javascript函数的值

Javascript

<script type="text/javascript">

    function displayservices() {
    PageMethods.GetCurrentTime(document.getElementById("Hello", OnSuccess);
    }
    function OnSuccess(response, userContext, methodName) {
      alert(response);
    }

</script>

本文将进一步指导您

你知道用c#输出数据的方法吗?你想实现什么还不清楚。您想从客户端(javascript)调用您的C#代码,还是从客户端(javascript)调用您的C#代码?如果不发出服务器请求,前者是不可能的,因为将任何奇怪的数据放在服务器上是非常有害的,后者是非常容易的。