服务端
using System;
using System.Collections.Generic;using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
//
/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
//前台
<script>
alert("aa");
$.ajax({
type: "post",
contentType: "application/json",
url: "WebService.asmx/HelloWorld",
data: "{}",
dataType: "json",
success: function (result) {
set(result.d);
}, error: function(x, e) {
alert(x.responseText);
}
});
function set(dd)
{
alert(dd);
}
</script>