手机
当前位置:查字典教程网 >软件教程 >编程开发 >Asp.net中用 AJAX调用后台静态的方法总结
Asp.net中用 AJAX调用后台静态的方法总结
摘要:从客户端调用后台静态方法1.AjaxLibrary方式C#代码:[WebMethod]publicstaticDateTimeGetCurr...

从客户端调用后台静态方法

1.Ajax Library方式

C#代码:

[WebMethod]

public static DateTime GetCurrentTime(string str)

{

return DateTime.Now;

}

JS代码:

<form id="form1" runat="server">

<script language=javascript type="text/javascript">

function GetCurrentTime1() {

PageMethods.GetCurrentTime('NewEgg ajax training', CheckIsSuccess);

}

function CheckIsSuccess(result) {

alert(result);

}

</script>

<div>

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">

</asp:ScriptManager>

<input id="Button1" type="button" value="客户端控件调用服务器端的方法" onclick="GetCurrentTime1()" />

</div>

</form>

说明:

C#方法必须加 "[WebMethod]"

前台页面必须使用引用 服务器控件

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">

</asp:ScriptManager>

调用方法: PageMethods.后台方法名(参数[,参数....], 成功后调用的方法名);

Ajax Library

Asp.net中用 AJAX调用后台静态的方法总结1

Asp.net中用 AJAX调用后台静态的方法总结2

2. jQuery方式 C#代码:

[WebMethod]

public static string ABC(string ABC)

{

return ABC;

}

JS代码:

$().ready(

function() {

$("#AjaxDemo").click(function() {

$.ajax({

type: "POST",

url: "Default.aspx/ABC",

data: "{'ABC':'test'}",

contentType: "application/json; charset=utf-8",

success: function(msg) {alert(msg); }

})

})

}

)

说明: 必须引用jQuery库文件.

3. 还有一种好像是要引用AJAX.dll文件的. 在后台注册前台方法. 这个好像在.net2.0的时候用的比较多. 具体没仔细研究.

还望有其他更简单方法的同学互相交流下~

【Asp.net中用 AJAX调用后台静态的方法总结】相关文章:

Sublime Text 2中文显示乱码的解决方法

windows任务管理器中隐藏进程的方法

Lazarus优化编译后文件大小的方法

使用oracle的SQL Developer创建用户的方法

xcode升级后ios9.0不能使用http协议的版本的解决方法介绍

win server 2008r2禁用远程连接设置方法分享

vs2012能编写c语言吗? VS2012编写c语言的方法

避免重装delphi 重装操作系统后的处理方法

Eclipse提示乱码问题的解决方法

在SharePoint中编写调用Excel Services的Filter Consumer方法

精品推荐
分类导航