Ajax调用不打的断点,但仍然成功的功能 [英] ajax call doesn't hit breakpoint but continues to success function

查看:512
本文介绍了Ajax调用不打的断点,但仍然成功的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的Ajax调用。这是我第一次遇到此问题。首先,我的行动断点没有被击中。第二,成功功能正在被执行。第三,我storeList /数据的价值是整个主体内容全code。这可能是造成我的行为没有被发现。

  $。阿贾克斯({
  键入:POST,
  网址:'/报告/ GetStoreFranchiseList franchiseId =?'+ franchiseId,
  成功:函数(storeList){
    执行console.log(storeList);
    VAR appendStr =<李>< A HREF =#的onclick = changeStore('所有','全部')GT;所有< / A>< /李>中;
    // $每个(storeList,功能(K,V){
    //执行console.log(V);
    // appendStr + =<李>< A HREF =#的onclick = changeStore('+ v.Id +,+ v.StoreName +)>中+ v.StoreName +&所述; / a取代;&所述; /利>中;
    //});
    执行console.log(appendStr);
    $(rptStoreDdl。)的HTML(appendStr)。
    $(#rptStoreDdlDv)removeClass移除()addClass(BTN-组)。;
  }
});
 

当我尝试在取消对每个函数,我得到这个错误:未捕获的类型错误:无法使用'在'运营商的#&LT搜索21748;错误>

显然,因为数据是错误的。任何想法家伙?谢谢!

编辑:

尝试通过小提琴手访问它,我得到这个:<?code> /错误/ NOTFOUND aspxerrorpath = /报告/ GetStoreFranchiseList

有没有发现这会触发我的客户错误。我真的不知道为什么没有找到我的行动。

控制器操作:

  [的InPrivate]
公共类ReportsController:控制器
{
    [HTTPGET]
    公共JsonResult GetStoreFranchiseList(字符串franchiseId)
    {
        VAR数据=新的名单,其中,商店和GT;();

        如果(WebUser.Franchisees =空&安培;!&安培; WebUser.Franchisees.Count()大于0)
        {
            数据= WebUser.Franchisees.FirstOrDefault(A =&GT; a.Id == franchiseId).Stores;
        }

        返回JSON(数据,JsonRequestBehavior.AllowGet);
    }
}
 

解决方案

更​​可能的一种无声的异常正在提高。我也遇到了这个完全一样的问题。值得一提的是,并非所有的异常将触发运行时错误,从浏览器/客户端它可能会出现一个有效的返回类型已经归还。就我而言,我能够使用Visual Studio的智能跟踪功能嗅出以下沉默异常:

的JSON请求是太大,无法反序列化

这给了我,我需要通过这个其他堆栈溢出响应

要解决这个问题的线索

我建议尝试使用的终极版本的Visual Studio附带的IntelliTrace,看看一些类似的异常干扰了你的服务器端code,最终欺骗客户,以为有效的响应返回。

最好的运气

I have this ajax call. This is the first time I'm experiencing this problem. First, the break point on my action is not being hit. Second, the success function is being executed. Third, the value of my storeList/data is the whole code of the whole body content. This might be caused of my action not being found.

$.ajax({
  type: 'POST',
  url: '/reports/GetStoreFranchiseList?franchiseId=' + franchiseId,
  success: function (storeList) {
    console.log(storeList);
    var appendStr = "<li><a href='#' onclick=changeStore('All', 'All')>All</a></li>";
    // $.each(storeList, function (k, v) {
    //   console.log(v);
    //   appendStr += "<li><a href='#' onclick=changeStore('" + v.Id + "','" + v.StoreName + "')>" + v.StoreName + "</a></li>";
    // });
    console.log(appendStr);
    $(".rptStoreDdl").html(appendStr);
    $("#rptStoreDdlDv").removeClass().addClass("btn-group");
  }
});

When I try uncommenting the each function, I get this error: Uncaught TypeError: Cannot use 'in' operator to search for '21748' in #<error>

Obviously because the data is wrong. Any Ideas guys? Thanks!

EDIT:

Tried accessing it via fiddler and I'm getting this: /Error/NotFound?aspxerrorpath=/reports/GetStoreFranchiseList

This triggers my customer error for not found. I'm really not sure why my action is not found.

Controller action:

[InPrivate]
public class ReportsController : Controller
{
    [HttpGet]
    public JsonResult GetStoreFranchiseList(string franchiseId)
    {
        var data = new List<Store>();

        if(WebUser.Franchisees != null && WebUser.Franchisees.Count() > 0)
        {
            data = WebUser.Franchisees.FirstOrDefault(a => a.Id == franchiseId).Stores;
        }

        return Json(data, JsonRequestBehavior.AllowGet);
    }
}

解决方案

More than likely a silent exception is being raised. I also encountered this exact same problem. It is worth noting that, not all exceptions will trigger a run-time error, from the browser/client it may appear that a valid return type has been returned. In my case, I was able to use the Intellitrace feature of Visual Studio to sniff out the following silent exception:

"The JSON request was too large to be deserialized"

That gave me the clues I needed to fix the issue via this other Stack Overflow response

I suggest trying to use the Ultimate version of Visual Studio which comes with Intellitrace to see if some similar exception is interfering with your server side code and ultimately tricking the client into thinking a valid response was returned.

Best of luck

这篇关于Ajax调用不打的断点,但仍然成功的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆