js页面:
try {
$.ajax({
type: "post",
contentType: "application/json;utf-8",
url: "WebService.asmx/HelloWorld",
data: '',
datatype: "json",
success: function (msg) {
var a = msg;
}
});
} catch (e) {
alert(e.message);
}
WebService.asmx文件:
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
[System.Web.Script.Services.ScriptService]
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
配置文件web.config:
在<system.web></system.web> 节点内添加
<webSer