Validation with AJAX?
Validation with AJAX?
Hi there, I am kinda new to jQuery but I love it! I am having a small problem with the validation plugin and AJAX. Below you see two blocks of code. The first is a simple ajax call, as you can see i tried adding the validation to this block of code. The result is that the AJAX call works great, but it completely skips the validation plugin. So the second block of code contains an IF statement to detect if the form is valid, and if so it is suppose to start the AJAX call. The result here is that validation occurs, but everything inside the IF statement doesn't work. You can view a live install of this code at
http://mocr.at/
Any help with this would be very appreciated.
- <script type="text/javascript">
jQuery(document).ready( function($) {
$("#contact-form").validate();
$("#send").click( function() {
$('#contact-form-wrapper').addClass('loading');
$('#contact-form-wrapper').empty();
$.ajax({
type: "POST",
url: "http://mocr.at/wp-admin/admin-ajax.php",
data: "action=process_form&contact_form=14&name=a&email=a&address=a&address2=a&city=a&state=AL&zip=a&country=Afghanistan&phone=a&fax=a&url=a&subject=a&message=a",
success: function(data) {
$('#contact-form-wrapper').removeClass('loading');
$('#contact-form-wrapper').html(data);
}
});
});
});
</script>
- <script type="text/javascript">
jQuery(document).ready( function($) {
$("#contact-form").validate();
$("#send").click( function() {
if ($("contact-form").valid() == true){
$('#contact-form-wrapper').addClass('loading');
$('#contact-form-wrapper').empty();
$.ajax({
type: "POST",
url: "http://mocr.at/wp-admin/admin-ajax.php",
data: "action=process_form&contact_form=14&name=a&email=a&address=a&address2=a&city=a&state=AL&zip=a&country=Afghanistan&phone=a&fax=a&url=a&subject=a&message=a",
success: function(data) {
$('#contact-form-wrapper').removeClass('loading');
$('#contact-form-wrapper').html(data);
}
});
}
});
});
<script>