Last active
November 21, 2020 10:40
-
-
Save sudopower/76fa3058e8e7e39d1f91c70767d97939 to your computer and use it in GitHub Desktop.
simple form w async call to backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="foo"> | |
<input type="text" name="name"> | |
<!-- | |
.... | |
--> | |
</form> | |
<script> | |
//callback doesn't run if HTML validation fails | |
$('form').submit(function(event) { | |
event.preventDefault(); | |
var $form = $(this); | |
var form_id = $form.attr('id'); | |
webinar_setup(form_id); | |
}); | |
function webinar_setup(form_id){ | |
event.preventDefault(); | |
var form = $('#'+form_id)[0]; | |
var data = new FormData(form); | |
$.ajax({ | |
type: "POST", | |
enctype: 'multipart/form-data', | |
url: "webinar_back.php", | |
data:data, | |
processData: false, | |
contentType: false, | |
cache: false, | |
timeout: 600000, | |
success: function (data) { | |
console.log(data); | |
//$('#success-alert).show(); | |
}, | |
error: function (e) { | |
console.log(e); | |
//$('#danger-alert).show(); | |
} | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment