【问题标题】:Jquery ajax success call but web method breakpoint not hitJquery ajax 成功调用但未命中 Web 方法断点
【发布时间】:2016-02-01 06:55:54
【问题描述】:

我有一个简单的设置。

jquery:

$.ajax({
  url: "/MyApp/MyHandler.ashx/MyMethod",
  success: function(result) {
    alert("sucess");
  },
  error: function() {
    alert('Error');
  }
});

和网络方法:

[System.Web.Services.WebMethod]
public static void MyMethod(){
  new AnotherClass(null).AnotherMethod(null, null); 
}

问题是调用成功警报,但在MyMethod 内未命中断点。

【问题讨论】:

  • 你不得不提到 Http 方法。喜欢类型:“获取”,
  • 控制台result,而不是提示“成功”。
  • 您是否尝试在网络方法上放置[HttpGet] 属性?
  • 尝试禁用JQueryAJAX缓存$.ajaxSetup({ cache: false });
  • @KovalenkoIvan 你能详细说明我为什么需要那个吗?

标签: javascript jquery asp.net ajax webmethod


【解决方案1】:

我遇到了同样的问题,这就是我最终不得不做的:

$.ajax({
   url: _url,
   data: '',
   dataType: 'json',
   contentType: 'application/json',
   type: 'POST',
   success: function(result) {
      alert("sucess");
   },
   error: function() {
      alert('Error');
   }
});

我的第一次尝试忽略了datadataTypecontentType;只有当我使用空字符串 (data: '') 设置 contentType: 'application/json' 时,它才最终起作用。多么令人头疼 - 希望这对其他人有帮助!

【讨论】:

    【解决方案2】:

    就我而言,问题出在 RoutingConfig 中。所以,在 RouteConfig 中的 App_Start 文件夹中对其进行排序,注释掉以下行

    //settings.AutoRedirectMode = RedirectMode.Permanent;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-12
      • 1970-01-01
      • 2017-10-24
      • 1970-01-01
      • 2014-07-31
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多