如何使用Jquery从我的代码后面调用方法? [英] How Can I Call A Method From My Code Behind Using Jquery?

查看:63
本文介绍了如何使用Jquery从我的代码后面调用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在后面注释了我的代码



[WebMethod]

public void Test()

{

//一些代码

}



并尝试在我的aspx页面中使用jquery调用此函数。 ...



但它无法使用....



什么是正确的方法实现这样的任务....提前感谢

I annotated my code behind with

[WebMethod]
public void Test()
{
// some code
}

and tried to call this function using jquery in my aspx page....

but it is not working....

What is the proper way to achieve a task like this.... Thanks in advance

推荐答案

您可以使用PageMethods.Test()从javascript(不带jquery)调用[WebMethod]。 />


要从javascript调用webmethod,你必须添加

< asp:ScriptManager ID =ScriptManager1runat =serverEnablePageMethods =true >

< / asp:ScriptManager>
你的aspx页面中的
You can call [WebMethod] from javascript (without jquery) with PageMethods.Test().

To call webmethod from javascript you have to add
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
in your aspx page.


定义方法:

public static void Test(){



}
define method :
public static void Test(){

}


这篇关于如何使用Jquery从我的代码后面调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆