Ajax not sending request

Asked

Viewed 35 times

-2

I can’t see where the mistake is.

inserir a descrição da imagem aqui

Accuse me of this mistake

$("#btnSalvarArquivo").on('click', function () {

    var EspecieArquivo = document.querySelector('input[name="rdEspecieArquivo"]:checked').value;
    var tipoArquivo = 0;

    var erros = 0;
    $("div").find('*').each(function () {
        var classe = $(this).attr("class");
        if (classe !== undefined) {
            var numItems = $('.has-error').length;
            if (numItems > 0) {
                return false;
            }
            else {
                debugger;
                if (EspecieArquivo === "0") {
                    var TipoArquivo = document.querySelector('input[name="rdTipoArquivo"]:checked').value;
                    console.log(TipoArquivo);
                    $.ajax({
                        type: 'GET',
                        url: 'ProtocoloLatam/Inserir',
                        dataType: 'JSON',

                        data: {

                            EspecieArquivo: EspecieArquivo,
                            TipoArquivo: TipoArquivo,
                            numeroProtocolo: $("#txtNumeroProtocolo").val(),
                            dataProtocolo: $("#txtDataProtocolo").val(),
                            prazoConclusao: $("#txtPrazoConclusao").val(),
                            colaborador: $("#txtNomeColaborador").val(),
                            bp: $("#txtBP").val(),
                            emailColaborador: $("#txtEmailColaborador").val(),
                            tipo: $("#cmbTipo").val(),
                            classificacao: $("#cmbClassificacao").val(),
                            torre: $("#cmbTorre").val(),
                            processo: $("#cmbProcesso").val(),
                            subprocesso: $("#cmbSubprocesso").val(),
                            cidadeOrigem: $("#cmbCidadeOrigem").val(),
                            quantidade: $("#txtQuantidade").val(),
                            ftp: $("#txtFTP").val(),
                            caixaNBox: $("#txtCaixaNBox").val()

                        }, success: function (data) {
                            setTimeout(function () {
                                toastr.success("Cadastrado com sucesso.");
                            }, 2000);


                        }
                    });
                } else if (EspecieArquivo === "1") {
                    var TipoArquivo = document.querySelector('input[name="rdTipoArquivo"]:checked').value;

                    $.ajax({
                        type: 'GET',
                        url: 'ProtocoloLatam/Inserir',
                        dataType: 'JSON',

                        data: {
                            EspecieArquivo: EspecieArquivo,
                            TipoArquivo: TipoArquivo,
                            numeroProtocolo: $("#txtNumeroProtocolo").val(),
                            dataProtocolo: $("#txtDataProtocolo").val(),
                            prazoConclusao: $("#txtPrazoConclusao").val(),
                            colaborador: $("#txtNomeColaborador").val(),
                            bp: $("#txtBP").val(),
                            emailColaborador: $("#txtEmailColaborador").val(),
                            tipo: $("#cmbTipoUnitario").val(),
                            classificacao: $("#cmbClassificacaoUnitario").val(),
                            torre: $("#cmbTorreUnitario").val(),
                            processo: $("#cmbProcessoUnitario").val(),
                            subprocesso: $("#cmbSubprocessoUnitario").val(),
                            cidadeOrigem: $("#cmbCidadeOrigemUnitario").val(),
                            ftp: $("#txtFTP").val(),
                            caixaNBox: $("#txtCaixaNBox").val()
                        }, success: function (data) {

                            $("#minhaModal").modal('hide');

                        }
                    }).done(function () {
                        toastr.success("Cadastrado com sucesso.");
                        setTimeout(4000);
                        window.location.reload();
                    });
                }


                return false;

            }
        }

    });
});

3 answers

2


Probably your code is breaking even before executing the Ajax request. Parecce that is unable to find the value property of the "var EspecieArquivo = document.querySelector('input[name="rdEspecieArquivo"]:checked').value; "

Try creating your variable without the value property and do a console.log to see how the element is doing.

var EspecieArquivo = document.querySelector('input[name="rdEspecieArquivo"]:checked');
console.log(EspecieArquivo);
  • Yeah, that’s right, I got this guy out of this place and it’s back up and running, thanks

  • Another thing expensive, you are mixing the syntax of jQuery with Vannila, this is not very indicated!

  • after will be standardized rs, I am in the testing phase

1

Probably the return of some call to querySelector() is null.

Try debugging the value of these variables:

var a = document.querySelector('input[name="rdEspecieArquivo"]:checked');
var b = document.querySelector('input[name="rdTipoArquivo"]:checked');

Test on the same console.

  • The problem was himself, thank you.

  • No problem, after I saw that they had already answered! :)

  • That checked value was throwing me into the hole, I couldn’t see it

1

Is that all the code you’re using? if yes, in the:

document.querySelector('input[name="rdEspecieArquivo"]:checked').value;

I haven’t found in any other part of your code that has that input nameless rdEspecieFile.

The same for the rdTipoArchive. So, as the integer n thinks, it gives null, and then you try to extract value from null...

  • Thank you, that’s right, he was in the wrong position

Browser other questions tagged

You are not signed in. Login or sign up in order to post.