fc123 fc123 - 5 months ago 140
Ajax Question

jQuery call to asp.net web method is not working

I have a asp.net web method like following

public string getDate()
return DateTime.Now.ToString();

And my jQuery ajax call is following

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)
// 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.



your web method should be static

public static string getDate() 
   return DateTime.Now.ToString();