Issues:
When showCurrentTime() is fired, the WebMethod GetCurrentTime() is never called.
The success function is firing and displaying an empty alert.
There is a script manager on the page.
JQuery is embedded.
Tried url: '<%= ResolveUrl("WebMethodTest2.aspx/GetCurrentTime") %>'. and get the same issues.
Tried enabling PageMethods then calling the WebMethod as follows and get the same issues.
PageMethods.GetCurrentTime(onSuccess, onError);
function onSuccess(resp) { alert(resp.d); }
function onError(resp) { alert(resp.d); }
Any help appreciated. Thanks.
function showCurrentTime() {
$.ajax({
type: "POST",
url: "WebMethodTest2.aspx/GetCurrentTime",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) { alert(response.d); },
failure: function (response) { alert(response.d); }
});
}
[WebMethod]
public static string GetCurrentTime()
{
return DateTime.Now.ToString();
}