John

John

  • NA
  • 928
  • 125.7k

How to call static web method using ajax

Jan 21 2017 4:56 AM
Getting alert as undefined in ajax
 
[WebMethod]
public List getDHEW()
{
if (st == ConnectionState.Closed)
con.Open();
List count = new List();
cmd = new SqlCommand(quy1,con);
int dcnt = (Int32)cmd.ExecuteScalar();
count.Add(dcnt);
cmd = new SqlCommand(quy2,con);
int ecnt = (Int32)cmd.ExecuteScalar();
count.Add(ecnt);
//JavaScriptSerializer ser = new JavaScriptSerializer();
//return ser.Serialize(count);
return count;
}
 
 
Ajax call
 
$.ajax({
type: "POST",
url: "WebService.asmx/getDHEW",
contentType: "application/json; charset=utf-8",
data: {},
dataType: "json",
success: function (data) {
alert(data.d);
},
error: function (response) {
alert(response.d);
}
});

Answers (3)