0

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();
    }
Rick
  • 33
  • 1
  • 4

1 Answers1

0

In case anyone else runs into this without realizing Asp.NET.FriendlyURLs are related to the issue.

In RouteConfig.cs comment out

  //settings.AutoRedirectMode = RedirectMode.Permanent;

Found the answer here: Authentication failed during call webmethod from jquery.ajx with AspNet.FriendlyUrls and AspNet.Identity

Community
  • 1
  • 1
Rick
  • 33
  • 1
  • 4