您的位置:首页 > Web前端 > JQuery

jquery 调用asp.net后台代码

2013-08-22 22:46 519 查看
1.需要引用对应的命名空间

System.Web.Services

2.后台方法;

必须是static 约束 必须添加[WebMethod()] 属性

示例:

<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script>
function a() {
$.ajax({
type: "post",
url: "WebForm1.aspx/GetString",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data.d);
var m = eval("("+data.d+")");
alert(m.name);
}
});
}
</script>

[System.Web.Services.WebMethod()]
public static string GetString()
{
return "{name:'lin'}";
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: