Send empty date to ajax

Asked

Viewed 68 times

1

I have in my form the following field:

<input type="date" class="inputTextMedio" name="dataBatismo" id="dataBatismo"/>

If chosen a date, it correctly sends the data to the ajax and write to Mysql normally occurs:

$.ajax({
    url: "_scripts/_php/_validacoes/cadastrarMembro.php",
    type: "POST",
    dataType: "json",
    data: {   
         dataCadastro : $("#dataCadastro").val(),
         nome : $("#nome").val(),
         apelido : $("#apelido").val(),
         nascimento : $("#nascimento").val(),
         telefone : $("#telefone").val(),
         celular : $("#celular").val(),
         bairro : $("#bairro").val(),
         endereco : $("#endereco").val(),
         email : $("#email").val(),
         sexo : $("#sexo").val(),
         estadoCivil : $("#estadoCivil").val(),
         dataBatismo : $("#dataBatismo").val(),
         bloqueado : $("#bloqueado").val(),
         batizadoFora : $("#batizadoFora").val(),
         usuario : $("#usuario").val(),
         senha : $("#senha").val()
    },
    success: function (result) {
        alert('Resultado');
        if (result[0] == "Erro")
            $(".resposta").html(result[1]);
        else
            $(".resposta").html(result[1]);
    }
});

However, if no date is chosen in the field, the Ajax accepts nothing and no wheel.

What is wrong here?

One detail that may be relevant here is that the inspector, when a date is NOT chosen, nor does it send a single line. It is completely empty!

I also made the attempt below but without success:

dataBatismo : $("#dataBatismo").val() == "" ? "null" : $("#dataBatismo").val(),

And so:

dataBatismo : $("#dataBatismo").val() == "" ? "NULL" : $("#dataBatismo").val(),

And so:

dataBatismo : $("#dataBatismo").val() == "" ? 'null' : $("#dataBatismo").val(),

And so:

dataBatismo : $("#dataBatismo").val() == "" ? 'NULL' : $("#dataBatismo").val(),

And so:

dataBatismo : $("#dataBatismo").val() == "" ? null : $("#dataBatismo").val(),

And so:

dataBatismo : $("#dataBatismo").val() == "" ? NULL : $("#dataBatismo").val(),

Nothing works out.

Will I have to convert to text?

  • is using some kind of mask or plugin in the date field?

  • Try !$("#dataBatismo").val().trim() ? "null" : $("#dataBatismo").val(),

  • the problem was in php. I’m opening another question

  • opened: https://answall.com/questions/355323/receberendo-campo-nulo-ou-%C3%A3o-nulo

No answers

Browser other questions tagged

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