jquery
复制代码 代码如下:
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebForm2.aspx/GetUserName",
data: "{}",
dataType: "json", 编程客栈
success: function(){.......}
});
Jygeq
http://www.cppcns.com
复制代码 代码如下:
<%@ Page language="C#"%>
<script runat="server">
protected void Page_Load(object sender,EventArgs e){
Response.Charset="gb2312";
if(Request.Form["method"]=="Test")Test();
else if(Request.Form["method"]=="Test1")Test1();
else if(Request.Form["method"]=="Test2")Test2();
Rewww.cppcns.comsponse.Write("一般请求<br/>");
}
public void Test()
{
Response.Write("执行Test方法"+DateTime.Now);
Response.End();//停止其他输出
}
public void Test1()
{
Response.Write("执行Test1方法"+DateTime.Now);
Response.End();//停止其他输出
}
public void Test2()
{
Response.Write("执行Test2方法"+DateTime.Now);
Response.End();//停止其他输出
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<input type="button" value="调用Test" onclick="CallMethod('Test')"/><input type="button" value="调用Test1"
onclick="CallMethod('Test1')"/><input type="button" value="调用Test2" onclick="CallMethod('Test2')"/>
<script type="text/javascript">
function CallMethod(method){
$.ajax(
{
type: "POST",
url: "test.aspx",
data:{method:method},
success:function(msg){alert(msg);},
error: function(){alert('出错了');}
}
)
}
$(document).ready(function(){
$.ajax(
{
twww.cppcns.comype: "POST",
url: "test.aspx",
data:{method:"Test"},
success:function(msg){alert("$(document).ready执行方法Test返回结果\n\n\n"+msg);},
error: function(){alert('出错了');}
}
);
})
</script>
</body>
</html>
本文标题: 用juery的ajax方法调用aspx.cs页面中的webmethod方法示例
本文地址: http://www.cppcns.com/wangluo/ajax/97903.html
© 著作权归作者所有
举报
发表评论
0/200