Ich möchte diese Funktion universell machen, basierend auf Button ID. Es funktioniert derzeit (etwas) in einem Div, aber es gibt mehrere Formen in mehreren Divs auf der Seite. Bitte raten ...
var frm_submit_event = function(e) {
var $this = $(this); // the button
var frm = $('#' + selected_form_div + " form");
console.log(frm);
console.log(frm.serialize());
e.preventDefault();
$.ajax({
type: "POST",
url: "classes/forms/ajaxPost.php",
data: frm.serialize(),
dataType: "text",
success: function($result) {
//var obj = jQuery.parseJSON(data); if the dataType is not specified as json uncomment this
$('#' + selected_form_div).html($result);
},
error: function() {
alert('error handing here');
}
});
}
$(document).on("click", '.frm_submit_btn', frm_submit_event);
nicht sicher, wo man von hier geht ...
'var frm = $ this.closest ("Form");' wird die Form erhalten, dass die Schaltfläche in ist – Barmar
Was 'selected_form_div' ist.? – Barmar
'$ ('#' + selected_form_div) .html ($ result);' überschreibt das Formular, da es sich im DIV befindet. Willst du das wirklich? – Barmar