Created
June 29, 2018 11:03
-
-
Save svgerasimov/f1a64dafc8503e070ad03445f964d594 to your computer and use it in GitHub Desktop.
ajax
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
<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