Problems with function when trying to perform deletion

1

I have a problem deleting it and I get an error message in the console, my script looks like this:

<form action="" id="frmDeleta" class="smart-form"> 
  <button type="submit" class="btn btn-danger"> Excluir </button>
  <input name="IdEvento" type="hidden" value="<?php echo $IdEvento; ?>">
</form>
    $(document).ready(function () {             

            $("#frmDeleta")({               
                // NÃO ALTERAR O CÓDIGO 
                errorPlacement: function (error, element) {
                    error.insertAfter(element.parent());
                },
                submitHandler: function (form) {
                    var data = $(form).serialize();                 
                    // console.log(data);                   
                    $.ajax({
                        type: 'POST',
                        url: 'pDeletaAgendamento.php',
                        data: data,
                        dataType: 'json',
                        beforeSend: function () {
                            $("#msgResult").html('×AVISO! Enviando...');
                        },
                        success: function (response) {
                            if (response.codigo == "1") {
                                $("#msgResult").html('×AVISO!' + response.mensagem + '');
                                // RESETANDO O FORMULÁRIO APÓS GRAVAÇÃO
                                $('#frmDeleta').each(function () {
                                    this.reset();   
                                });

                            } else {
                                $("#msgResult").html('×ATENÇÃO! ' + response.mensagem + '');
                            }
                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                            // console.warn(xhr.responseText);
                            console.log(xhr, ajaxOptions, thrownError);
                            $("#msgResult").html('×ATENÇÃO! Ocorreu um erro ao tentar enviar o Agendamento. Contate o departamento de TI.');
                        }
                    });
                    return false;
                }

            });

    }); 

But on my console I'm getting the following message:

    
asked by anonymous 14.10.2016 / 14:53

1 answer

1

Two errors visible in your code,

1 ° the tag #frmDeleta refers to a name form, not a id

2 ° I believe you wanted to use the submit function using jquery , which I know there is no call of type $("#frmDeleta")({ (correct me if I'm wrong)

I actually believe you are trying to use the validate plugin, the correct syntax would be: $("#frmDeleta").validate({

$(document).ready(function() {
  $("#frmDeleta").validate({
    // NÃO ALTERAR O CÓDIGO 
    errorPlacement: function(error, element) {
      error.insertAfter(element.parent());
    },
    submitHandler: function(form) {
      var data = $(form).serialize();
      // console.log(data);                   
      $.ajax({
        type: 'POST',
        url: 'pDeletaAgendamento.php',
        data: data,
        dataType: 'json',
        beforeSend: function() {
          $("#msgResult").html('×AVISO! Enviando...');
        },
        success: function(response) {
          if (response.codigo == "1") {
            $("#msgResult").html('×AVISO!' + response.mensagem + '');
            // RESETANDO O FORMULÁRIO APÓS GRAVAÇÃO
            $('#frmDeleta').each(function() {
              this.reset();
            });
          } else {
            $("#msgResult").html('×ATENÇÃO! ' + response.mensagem + '');
          }
        },
        error: function(xhr, ajaxOptions, thrownError) {
          // console.warn(xhr.responseText);
          console.log(xhr, ajaxOptions, thrownError);
          $("#msgResult").html('×ATENÇÃO! Ocorreu um erro ao tentar enviar o Agendamento. Contate o departamento de TI.');
        }
      });
      return false;
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>

<form action="" id="frmDeleta" name="frmDeleta" class="smart-form">
  <button type="submit" class="btn btn-danger">Excluir</button>
  <input name="IdEvento" type="hidden" value="<?php echo $IdEvento; ?>">
</form>
    
14.10.2016 / 15:17