Answer the question
In order to leave comments, you need to log in
How to display ajax error in block?
Good day.
Unable to display reverse text on the page.
HTML:
<div class="form_line">
<div class="send_page button">Отправить</div> <!-- Кнопка отправки формы -->
<div class="form_error"></div> <!-- Блок где выводится ошибка-->
</div>
$(function() {
$(".send_page").click(function(){
$.ajax({
type: "POST",
url: "/main/hand.php",
data: $(this).closest("form").serialize(),
cache: false,
success: function(msg){ $(this).next().html(msg); } // берем кнопку, ищем следующий элемент, вставляем в него текст ошибки
});
});
});
success: function(msg){ $(".form_error").html(msg); }
Answer the question
In order to leave comments, you need to log in
In the $(this) ajax callback, $(this) is not a link to the
clicked
element
.
Thank you very much for your help!
$(function() {
$(".send_page").click(function(){
var form = $(this).closest("form");
$.ajax({
type: "POST",
url: "/main/hand.php",
data: form.serialize(),
cache: false,
success: function(msg){ form.find(".form_error").fadeIn('show').html(msg); }
});
return false;
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question