简体   繁体   English

返回“文本”的Ajax错误

[英]Ajax Error returning “Text”

I have this Ajax code running on my web page (asp.net razor) 我的网页上正在运行此Ajax代码(asp.net剃须刀)

$(document).on('click', '#search-results tr', function (event) {
    //Add to cart
    var id = $(this).find('#SKU').val();
    var userId = $('#ID').val();
    $.ajax({
        url: "/orders/AddtoCart",
        type: 'POST',
        cache: false,
        dataType: 'json',
        data: { "productId": id, "Quantity": 1, "UserID": userId, "Description": "" },
        success: function (data) {
            console.debug("Added to cart");
            //ajax call to DraftOrderDetailsLineItems to refresh the lines 
            $.get('/Orders/DraftOrderDetailsLineItems/', { customerId: data.id }, function (data) {
                $("#draftOrderItems").html(data);
            })
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.error("[Error in Ajax Request, Add To Cart] Code:" + jqXHR.status + " Error:" + errorThrown + " \nText Status:" + jqXHR.responseText);
        }
    });
});

I put a breakpoint in my controller and it is calling the AddtoCart method just fine. 我在控制器中放置了一个断点,它正在调用AddtoCart方法。 However when I look in my console I am getting this error: 但是,当我在控制台中查看时,出现此错误:

VM247 DraftOrderDetails.js:19 [Error in Ajax Request, Add To Cart] Code:0 Error: Text Status:undefined VM247 DraftOrderDetails.js:19 [Ajax请求中的错误,添加到购物车]代码:0错误:文本状态:未定义

I have been looking this over and I just can't seem to find out what is going one. 我一直在寻找这一点,但似乎无法找出正在发生的事情。

Looks like this was an error from the controller of all places. 看来这是来自所有位置的控制器的错误。 The controller was throwing an uncaught error which was spitting out this ajax error (which technically wasn't an error). 控制器抛出一个未捕获的错误,该错误吐出了这个ajax错误(从技术上讲这不是错误)。 Once we trapped the error in the controller, the ajax error went away. 一旦我们在控制器中捕获了错误,ajax错误就消失了。 Just posting this in case someone else sees this and hopefully will be pointed to another possible cause of the error. 如果其他人看到此消息,则只是将其发布,并希望将其指向导致该错误的另一个可能原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM