0
I got the following js
  $("#contato").on("submit", function () {
    if($('#descricao').val() == "")   {     //verifica apena o texto
        alert("Descrição não está preenchida!");
        $('#descricao').siblings().each(function(){
          if ($(this).children('iframe').length){
             var iframe=$(this).children('iframe')[0];
             iframe.contentWindow.focus();
          }
       });
       return false;
    } 
    $.ajax({
     url: "_required/email.php",
     type: "POST",
     data: $("#contato").serialize(),
     success: function(retorno){
        if (retorno == "OK") {
          resposta = "E-mail enviado com sucesso!";
        } else {
          resposta = "Erro no envio do E-mail";
        }
       $(".resposta").css("display", "block");
       $(".resposta").html(resposta);             
     }
    });
    return false;
  }); 
This validates sending the form.
I switched the Ajax
$.ajax({
 url: "_required/email.php",
 type: "POST",
 data: $("#contato").serialize(),
 success: function(retorno){
    if (retorno == "OK") {
      resposta = "E-mail enviado com sucesso!";
    } else {
      resposta = "Erro no envio do E-mail";
    }
   $(".resposta").css("display", "block");
   $(".resposta").html(resposta);             
 }
});
For
$(this).load ("_required/email.php", $("#contato").serialize(), function(result) {
    if (result == "OK") {
      resposta = "E-mail enviado com sucesso!";
    } else {
      resposta = "Erro no envio do E-mail";
    }
   $(".resposta").css("display", "block");
   $(".resposta").html(resposta);             
});
Thus remaining:
  $("#contato").on("submit", function () {
    if($('#descricao').val() == "")   {     //verifica apena o texto
        alert("Descrição não está preenchida!");
        $('#descricao').siblings().each(function(){
          if ($(this).children('iframe').length){
             var iframe=$(this).children('iframe')[0];
             iframe.contentWindow.focus();
          }
       });
       return false;
    } 
    $(this).load ("_required/email.php", $("#contato").serialize(), function(result) {
        if (result == "OK") {
          resposta = "E-mail enviado com sucesso!";
        } else {
          resposta = "Erro no envio do E-mail";
        }
       $(".resposta").css("display", "block");
       $(".resposta").html(resposta);             
    });
    return false;
  }); 
But in this way, the form is being submitted and with ajax is not subject to return false which is my goal.
Where am I going wrong?
I used to, too:
$(this).post("_required/email.php",{ 
   assunto : $("#assunto").val(),
   assunto : $("#nome").val(),
   assunto : $("#email").val(),
   assunto : $("#telefome").val(),
   assunto : $("#descricao").val(),
   assunto : $("#qual").val()
 },function(result){
    if (result == "OK") {
      resposta = "E-mail enviado com sucesso!";
    } else {
      resposta = "Erro no envio do E-mail";
    }
   $(".resposta").css("display", "block");
   $(".resposta").html(resposta);             
})
But that way until submitting the page and changing the page changed.
Got it! O . post() so it shouldn’t be asynchronous. It’s not even?
– Carlos Rocha
Any http request, even if not done via
$.ajax()is asynchronous.– Giovane
Ué. but then why are you leaving the page when I use it. . post() and . load()? That was the question’s question!
– Carlos Rocha
He’s updating the page?
– Giovane
no! is switching pages as if it were a Submit straight from the form.
– Carlos Rocha
Would you use the
return falseto prevent the standard behavior of a form. Of a.preventDefault()at the Ubmit event– Giovane
created an answer. has how you comment on it for me?
– Carlos Rocha
It was bad, I read in a hurry I got everything wrong and went to update my answer because I understood that I wanted to give better examples.
– Giovane