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'}";
}