$(function aa() {//参数一个都不能少
$.ajax({
type: "post", //要用这,GET出错
contentType: "application/json", //返回值,指定类型
url: "WebService.asmx/H",
data: "{}", //参数为空,不为就是:str:'aa',strs:''
dataType: "json", //取数据时类型,不指定就是JSON格式的,若是指定为json则result不可看
success: function(result) {
// alert(result);
alert(result.d);
},
error: function(xhr, msg, e) { alert("错误" + msg); }
});
});
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string H()
{
return "Hello World";
}
}