AJAX always executes status === 0

0

An AJAX error status always returns 0, inserts correctly in my BD but does not show success message, shows error message when status === 0, I execute 3 AJAX functions in a click event of a button, both functions that are invoked are executed correctly, the AJAX function is the one that sends the message that is inside the condition status === 0

$("#btnGuardafactura").click(function (event) {
        
        var cantidadSim = $("#txtValorTotalSim").val();
        var cantidadArticulo = $("#txtValorTotalArticulo").val();
        //alert("guardar");
        var varFactura = $("#txtfactura").val();
        var varNombre = $("#txtNombre").val();
        var varApellidop = $("#txtApellidoA").val();
        var varApellidom = $("#txtApellidoM").val();
        var varFechaCompra = $("#txtfechaCompra").val();
        var varEmailu = $("#txtEmail").val();
        var varArchivo = $("#rutaPdf").val();

        if (cantidadSim == cantidadArticulo) {

            fn_Ajax_Articulo();
            fn_Ajax_sim();

            var cargando = $("#muestraSeccion").html("<center><img  src='../Images/cargando1.gif' height='50px' width='50px'/><br/>Un momento por favor...<center>");
            
            $.ajax({
                type: 'POST',
                url: 'guardarFactura',
                data: {
                    "factura": varFactura,
                    "nombre": varNombre,
                    "apellidop": varApellidop,
                    "apellidom": varApellidom,
                    "fechaCompra": varFechaCompra,
                    "emailUsuario": varEmailu,
                    "archivo":varArchivo
                },
                success: function (resultado) {
                    cargando.hide();                    
                    alert(resultado);                    

                },
                error: function (jqXHR, textStatus, errorThrown) {

                    if (jqXHR.status === 0) {

                        alert('Not connect: Verify Network.=(');

                    } else if (jqXHR.status == 404) {

                        alert('Requested page not found [404].');

                    } else if (jqXHR.status == 500) {

                        alert('Error Interno del Servidor [500].');

                    } else if (textStatus === 'parsererror') {

                        alert('Requested JSON parse failed.');

                    } else if (textStatus === 'timeout') {

                        alert('Time out error.');

                    } else if (textStatus === 'abort') {

                        alert('Ajax request aborted.');

                    } else {

                        alert('Uncaught Error: ' + jqXHR.responseText);

                    }

                }
            });


        } else {
            alert("La cantidad de articulos debe ser la misma que la cantidad de SIM")
            event.preventDefault();
        }


    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

error that appears printing the variables of .error (...) with console.log

    
asked by Ivxn 27.06.2016 в 23:34
source

2 answers

0

You are probably accessing a domain: port other than the one you launch the script. It is what is known as the policy of the same origin.

link

    
answered by 15.02.2017 в 11:56
0

Error 500 is due to the response you get this

  

string or binary data would be truncated

That is an sql error when you try to insert a field that has a length greater than the column created for example if you insert the column nombre char(5) This is a very long name, because it would give this error because the length exceeds the characters in the column

    
answered by 11.07.2018 в 11:36