1.方式一:在一个web页面中 [System.Web.Services.WebMethod],有点象webservers的方法!
前台:
返回的数据:
msg:Object {d: "Hello kevin"}
msg.d:"Hello kevin"
<script type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "WebForm2.aspx/GetString",
async: false,
data: "{'name':'kevin'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function (msg) { alert(msg.responseText); }
});
})
</script>
后台如下:
[System.Web.Services.WebMethod]
public static string GetString(string name)
{
return "Hello " + name;
}
因为是请求的静态方法,所以只能请求全局的静态变量,不能请求其他的页面!
2.直接去请求一个一般处理程序!