WebMethod不被调用,但是ajax请求返回整个页面

时间:2019-09-02 11:10:03

标签: javascript c# jquery webforms

我正在使用jQuery调用服务器端方法。我的情况是检查浏览器上的用户活动,如果经过一定时间后仍未执行任何操作,则会调用超时功能,该超时功能将调用服务器端功能来注销用户。

我使用的是网络方法,并且已阅读了多个教程,但目前无法正常使用。 AJAX请求错误,并在响应中返回整个页面。

还请注意,我在网络方法功能中有一个断点,永远不会被击中。

$(function() {
  $(document).idleTimer(10000);

  $(document).on("idle.idleTimer", function(event, elem, obj) {
    $.ajax({
      type: 'POST',
      url: 'BasePage.aspx/ValidateUser',
      crossDomain: true,
      data: "{ 'foo': 'AJAX Test' }",
      contentType: "application/json; charset=utf-8",
      dataType: 'jsonp',
      success: function(data, status) {
        alert(status + " " + data.d)
      },
      error: function(xhr, status, error) {
        alert("error!")
      }
    });
  });

  $(document).on("active.idleTimer", function(event, elem, obj, triggerevent) {
    // function you want to fire when the user becomes active again
  });
});
[System.Web.Services.WebMethod]
public static void ValidateUser(string foo) 
{
  // breakpoint not being hit
}

我在母版页中设置了我的脚本管理器,如下所示:

<asp:ScriptManager runat="server" EnablePageMethods="True">

0 个答案:

没有答案