Answer the question
In order to leave comments, you need to log in
Ajax handler works for all forms on the page. How to make an exception for one form?
I have 3 forms on my site. Successfully processed and sent to a common handler. It is necessary that the first form works through its ajax handler.
$(document).ready(function () {
$("form").submit(function () {
// Получение ID формы
var formID = $(this).attr('id');
// Добавление решётки к имени ID
var formNm = $('#' + formID);
$.ajax({
type: "POST",
url: 'mail.php',
data: formNm.serialize(),
success: function (data) {
// Вывод текста результата отправки
$(formNm).html(data);
},
error: function (jqXHR, text, error) {
// Вывод текста ошибки отправки
$(formNm).html(error);
}
});
return false;
});
});
var formIDfirst = $(this).attr('id');
if ((formIDfirst != 'main-form')) {
Answer the question
In order to leave comments, you need to log in
The easiest way is to change the selector so that the handler is hung up only on the second two.
Add a class to them, for example, and instead write
Or, without adding the class: , but this is worse in terms of support and understanding of what is happening on the page in general.
example: https://jsfiddle.net/L39uaxth/$("form").submit(...)
$(".myClass").submit(...)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question