Created
June 16, 2018 13:49
-
-
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
This file contains hidden or 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
////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