无法使用JQuery调用Web方法

时间:2014-07-31 07:01:37

标签: jquery ajax webmethod

我创建了一个名为proxy.cs的类,并在此添加了一个方法,现在想从jquery中调用它。那么我怎么做呢?课程代码是:

public class proxy : System.Web.Services.WebService
    {
        [System.Web.Services.WebMethod(BufferResponse = false)]
        public string GetBigData()
        {
            return "hi welcome";//implementation code
        }
    }

以下脚本功能无效。

 function test(){                  
           $.ajax(
            {
                url: '/proxy/GetBigData',
                type: 'POST',
                contentType: 'application/json;charset=utf-8',
                data: "{}",
                success: function (response) {
                },
                failure: function (response) {
                }
            });

         }

1 个答案:

答案 0 :(得分:0)

使用以下Ajax代码

$.ajax({
           type: "GET",
           url: '/proxy/GetBigData',
           data: null,
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           processdata: true,
           success: function (data) {
               console.log(data);
           },
           error: function (message) {
               console.log("error", message);
           }
       });