Skip to content

Instantly share code, notes, and snippets.

@svgerasimov
Created June 29, 2018 11:03
Show Gist options
  • Save svgerasimov/f1a64dafc8503e070ad03445f964d594 to your computer and use it in GitHub Desktop.
Save svgerasimov/f1a64dafc8503e070ad03445f964d594 to your computer and use it in GitHub Desktop.
ajax
<script type="text/javascript">
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() { return false; });
$("#send").on("click", function() {
var form = $(this);
var phoneval = $("#phone").val();
if (phoneval < 4) {
$("#phone").addClass("error");
}
else if (phoneval >= 4) {
$("#phone").removeClass("error");
}
if (phoneval >= 4) {
$("#send").replaceWith("<em>отправка...</em>");
var myurl = 'http://pfish.ru/index.php';
$.ajax({
type: 'POST',
url: myurl,
data: $("#contact").serialize(),
beforeSend: function (data) {
form.find('button[type="submit"]').attr('disabled', 'disabled');
},
success: function (data) {
$("#contact").fadeOut("fast", function () {
$(this).before("<p><strong>Мы вам перезвоним в ближайшее время :)</strong></p>");
setTimeout("$.fancybox.close()", 2000);
});
},
error: function(jqXHR) {
console.log(jqXHR['status'] + ": " + jqXHR['statusText']);
},
complete: function (data) {
form.find('button[type="submit"]').prop('disabled', false);
}
});
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment