我有一个default.aspx.cs,其中包含要调用的web方法,并且我的js文件包含我的jquery ajax。我无法打电话给网络方法。
这是我的default.aspx.cs:
protected void Page_Load(object sender, EventArgs e) { string[] MyArray = new string[1]; MyArray[0] = "My Value"; Grid1D.DataSource = MyArray; Grid1D.DataBind(); } [WebMethod] public Details[] getDetails(string columnname, string inputVal) { List<Details> list = new List<Details>(); DbAccess dbacc = new DbAccess(); DataTable dt = dbacc.getReportDetails(columnname, inputVal); foreach (DataRow row in dt.Rows) { Details _Details = new Details(); _Details.memid = row["memid"].ToString(); _Details.usrname = row["usrname"].ToString(); _Details.fullname = row["fullname"].ToString(); _Details.fname = row["fname"].ToString(); _Details.mname = row["mname"].ToString(); _Details.lname = row["lname"].ToString(); _Details.bdate = row["bdate"].ToString(); _Details.address = row["address"].ToString(); _Details.sponsorid = row["sponsor_id"].ToString(); _Details.parentid = row["parent_id"].ToString(); _Details.placement = row["placement"].ToString(); _Details.datejoined = row["date_joined"].ToString(); list.Add(_Details); } Grid1D.DataSource = list.ToArray(); Grid1D.DataBind(); return list.ToArray(); }
这是我的js文件:
function retrieveReportData() { var columnName = $("#ddlFilters").val(); var input = $("#tags").val(); if (columnName != "Select") { var Data = JSON.stringify({ columnname: columnName, inputVal: input }); alert(Data); $.ajax({ url: "Default.aspx/getDetails", data: Data, type: "POST", dataType: "json", contentType: "application/json; charset=utf-8", success: function (mydata) { alert(mydata.d); } }); } else alert("Please choose search filter"); }
您可能会注意到,我正在提醒我的数据,以确保我有正确的值发送给我的web方法。但是就像我说的那样,它无法调用我的web方法,并且不在我的Ajax中继续执行我的成功功能。救命!谢谢!:)
您的webmethod必须是static。
static
[WebMethod] public static Details[] getDetails(string columnname, string inputVal)