I have a asp.net web method like following
[WebMethod]
public string getDate()
{
return DateTime.Now.ToString();
}
And my jQuery ajax call is following
$.ajax({
type: "POST",
url: "jqueryAjax/Default.aspx/getDate",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert(errorThrown+"what's wrong?"+XMLHttpRequest);
},
success: function (msg)
{
alert(msg);
// Do something interesting here.
}
});
For some reason my jQuery ajax error handler is getting called. success method is not calling.
Any help will be appreciated.
Thanks
your web method should be static
[WebMethod]
public static string getDate()
{
return DateTime.Now.ToString();
}