POST requests AJAX ASP net MVC

1

Good afternoon, I'm having a little doubt, I'm doing a POST request with AJAX in ASP net MVC and everything works fine, but in firefox I get an error in the console

However,inchromethiserrordoesnotappear.Hereistherequisitioncode:

functionadicionaCarrinho(quantidade,codigoProduto){vartoken=$('input[name=__RequestVerificationToken]').val();varheader={};header['RequestVerificationToken']=token;$.ajax({url:"/Produto/AddCarrinho",
        type: 'POST',
        data: { __RequestVerificationToken: token, codigoProduto: codigoProduto, quantidade: quantidade},
        headers: header,
        success: function (data) {
            getCookie();
        },
        error: function (data) {

            console.log('Error' + data);
        }
    });
}

and here is the controller code

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult AddCarrinho(string codigoProduto, int quantidade)
        {
            HttpCookie cart = Request.Cookies.Get("Cart");
            HttpCookie cartQtd = Request.Cookies.Get("CartQtd");

            if(cart != null)
            {
                _pedidoItensDAO.InsereItem(_pedidoDAO.RetornaPedido(cart.Value), codigoProduto, quantidade);
                cartQtd.Value = (Convert.ToInt32(cartQtd.Value) + quantidade).ToString();
                Response.Cookies.Add(cartQtd);
            }
            else
            {
                var token = Guid.NewGuid().ToString();
                _pedidoDAO.InserePedido(token);
                _pedidoItensDAO.InsereItem(_pedidoDAO.RetornaPedido(token), codigoProduto, quantidade);
                Response.Cookies.Add(new HttpCookie("Cart", token));
                Response.Cookies.Add(new HttpCookie("CartQtd", quantidade.ToString()));
            }

            return new EmptyResult();
        }

Does anyone know the reason for the error in firefox?

    
asked by anonymous 09.10.2018 / 21:18

1 answer

1

Based on some research I found that:

  

The error message is only generated by FireFox when the   is blank. For some reason, .NET generates a type of   response of application/xml when creating an empty page. Firefox   parses the file as XML and finds no root element, sends   the error message.   Source: here

In your case you are returning a EmptyResult(); that returns a completely empty result. To solve the problem, return an object Json empty return Json(string.Empty)

    
09.10.2018 / 22:25