0
I’d like that after the $ajax ended, updated the tag div that has as an id #coments, for in that div load data from the database.
HTML
<div id="coments">
<!-- // Query dos comentários PAI -->
<div class="you-coment-post">
<div class="avatar">
<img src="logo-face.png" alt="">
</div>
<div class="box-you-write-post-coment">
<span class="title-you-post-coment">Ramon</span>
<p class="you-text-post-coment">
E aeeee </p>
</div>
</div>
<!-- // Fim do Bloco -->
</div>
AJAX
function checkKeyPai() {
var tamanho = $("#comentario-pai").val().length;
if (window.event.keyCode == 13) {
var textareaPai = $('#comentario-pai').val();
var posicao = $('#comentario-pai').attr("data-posicao");
var idUser = $('#comentario-pai').attr("data-idUser");
var idPost = $('#comentario-pai').attr("data-idPost");
if (tamanho < 10) {
alert("Você precisa digitar pelo menos 10 caracteres");
} else {
if (idUser == "") {
alert("Você precisa está logado!");
} else {
$.ajax({
url: "/addComentario.php",
type: "POST",
data: "textareaPai=" + textareaPai + "&idUser=" + idUser + "&idPost=" + idPost + "&posicao=" + posicao + "",
dataType: "html"
}).done(function(resposta) {
alert(resposta);
}).fail(function(jqXHR, textStatus ) {
alert("Request failed: " + textStatus);
}).always(function() {
console.log("completou");
});
}
}
}
}
You know what the methods represent
done,failandalwaysthat you used?– Woss
The . done is always executed, while . Success is only called if success occurs.
– ramon
And also that the done and fail methods are related to the return of the $.ajax. function only Always which have not understood much yet.
– ramon
The method
doneonly executed if the request was successful and it is in it that you should update thediv.– Woss
But that you have my question how I make this update, and that I am very beginner yet.
– ramon
It depends on what this "update" would be. Edit the question and add more details about it, explaining which is the
divand what will be the new content.– Woss