Aspx页面模拟WebService功能

在后台引入 using System.Web.Services 命名空间

然后在编写web服务方法:

1     [WebMethod]
2     public static string GetData(string time, string targetColumn)
3     {
4         return "我是一个位于Aspx页面的WebService方法";
5     }

前端用Ajax的Post方法发送请求:

 1 $.ajax({
 2             type: "post",
 3             url: url,
 4             datatype: "json",
 5             contentType: "application/json",
 6             data: requestData,
 7             success: function (obj){
 8                   console.debug(obj);
 9             },
10             error: function (message) {
11             }
12         });

这样执行这个Ajax方法就可以用Aspx页面处理WebService请求了。

原文地址:https://www.cnblogs.com/likeli/p/4892076.html