Skip to content

Instantly share code, notes, and snippets.

@pavlo-bondarchuk
Created June 16, 2018 13:49
Show Gist options
  • Save pavlo-bondarchuk/8ba412500cade3d129a9ce28d6d99770 to your computer and use it in GitHub Desktop.
Save pavlo-bondarchuk/8ba412500cade3d129a9ce28d6d99770 to your computer and use it in GitHub Desktop.
ajax form - clear form on success, block btn#submit, timeout redirect to other page
////ajax form, clear form on success,block btn#submit,timeout redirect
$(".app-form").submit(function(event){//form class
event.preventDefault();//stop default
submitForm();//send to function
});
function submitForm(){
var name = $("#name").val();//input id="name"
var tel = $("#tel").val();//input id="tel"
$.ajax({
type: "POST",
url: "sender.php",
data: "name=" + name + "&tel=" + tel,
success : function(data){
$("#appform")[0].reset();//reset form
$("#submit").attr('disabled', 'disabled');//block btn
setTimeout(function(){location.href="thank-you-page.html"} , 300);//redirect to thank-you-page
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment