ajax请求本页面后台方法


$.ajax({
url: "Default.aspx/Method",
data: "{name:'hh',password:'123'}",
type: "post",
dataType: "json",
contentType: "application/json;charset=utf-8",
success: function(msg) {

},
error: function(xhr) {
}
});

后台方法
[WebMethod]
public static string Method(string name,string password)
{
return "aa";
}

url:"本页面名称/方法名称";data的格式为json格式;dataType: "json";contentType:"application/json;charset=utf-8";msg.d通过.d属性来取服务端返回的数据
后台方法里的注意地方:
方法由[WebMethod]修饰;方法必须是公共的静态方法;方法里的参数名称必须与脚本里data的参数名一样,顺序可以不一样
原文地址:https://www.cnblogs.com/songling/p/2387907.html