0

I have a MVC app in which I'm using jQuery to call specific actions in a controller to add items to a cart.

Now, the app is running as it should, but when I'll leave the app to sit in the browser and comeback after lets say 1 hour, and I'm trying to add a item to the cart, clicking the button doesn't cause any action and I'm getting this error:

SCRIPT7002: XMLHttpRequest: Network Error 0x80700013, Could not complete the operation due to error 80700013.

This is the script which should be triggered:

$('button.submitButton').click(function() {
        var itemName2 = $(this).data('name');
        $.ajax({
            url: '@Url.Action("AddToCartAjax", "Cart")',
            data: { itemId: $(this).data('id'), categoryId: $(this).data('categoryid') },
            dataType: "json",
            type: 'POST',
            success: function (data) {                    
                UpdatePartialView(data); 
                $(".modal-body #cartTotalLabel").text('Order Total £' + data.Total);
                $(".modal-body #cartItemName").text(itemName2 + ' added');
                $('#createModal').modal('show');
                setTimeout(function () { $('#createModal').modal('hide'); }, 2000);
            }
        });
    }            
});

What should I do to fix this error?

halfer
  • 19,824
  • 17
  • 99
  • 186
Laziale
  • 7,965
  • 46
  • 146
  • 262

1 Answers1

0

This looks like a session timeout in ASP.Net, not around jQuery / js. I got the same behaviour in a project a few months ago.

You can even change the timeout value, or handle these problems when you met them, for example by this way: Handling session timeout in ajax calls (here they alert when the error happened) or even this ASP.NET MVC Session Expiration (here they alert when the timeout will happened).

Community
  • 1
  • 1
Nicolas R
  • 13,812
  • 2
  • 28
  • 57