Ich habe ein Formular in AJAX
funktioniert, aber wenn ich mehr als ein Formular auf der gleichen Seite haben, erscheint ein Fehler.AJAX-Formular senden ohne Aktualisierungsfehler
<script>
var fmx = jQuery.noConflict();
fmx(document).ready(function(){
fmx('form').on('submit', function (e) {
e.preventDefault();
fmx.ajax({
type: 'post',
url: 'https://www.webshop.com/post.php',
data: fmx('form').serialize(),
success: function() {
document.getElementById('#form_post').style.display = 'none';
document.getElementById('#form_result').style.display = '';
}
});
});
});
</script>
<div id="#form_post" style="display:inherit">
<form class="form_post">
<label for="post_email">FORM</label>
<input id="post_email" class="post_email" type="email" name="post_email" placeholder="[email protected]" required>
<input id="post_data" class="post_data" type="text" name="post_data" placeholder="MSG" required>
<input name="submit" type="submit" value="POST" >
</form>
</div>
<div id="#form_result" style="display:none"><br>Success.</div>
Ich habe versucht, einen #id zu wechseln, aber es funktioniert nicht mehr.
<script>
var fmx = jQuery.noConflict();
fmx(document).ready(function(){
fmx('#form').on('submit', function (e) {
e.preventDefault();
fmx.ajax({
type: 'post',
url: 'https://www.webshop.com/post.php',
data: fmx('#form').serialize(),
success: function() {
document.getElementById('#form_post').style.display = 'none';
document.getElementById('#form_result').style.display = '';
}
});
});
});
</script>
<form class="form_post" id="form">
Wie ein ID
auf diesem Formular do setzen?
Welchen Fehler bekommen Sie? – SLaks
IDs müssen eindeutig sein. – SLaks
Der HTML-Zusatz hat keine ID auf dem Formular. – Jonathan