fc123 fc123 - 1 year ago 325
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.


Answer Source

your web method should be static

public static string getDate() 
   return DateTime.Now.ToString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download