Created
December 4, 2009 16:53
-
-
Save mwunsch/249149 to your computer and use it in GitHub Desktop.
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
var Messages = { | |
loader: jQuery('<div class="loading">Loading...</div>'), | |
thanks: jQuery('<div class="success">Thanks! We\'ll stay in touch!</div>'), | |
error: jQuery('<div class="ajax-error">Oh no. Something really terrible happened</div>'), | |
}; | |
var contact_form = jQuery('#contact-form'); | |
var colorBox = jQuery.fn.colorbox; | |
jQuery('#email-form').validate({ | |
submitHandler: function(form) { | |
var $this = jQuery(form); | |
$this.hide(); //this hides the form | |
if (contact_form.find('.loading').length <= 0) { | |
contact_form.prepend(Messages.loader); | |
} else { | |
contact_form.find('.loading').show(); | |
} | |
colorBox.resize(); | |
jQuery.ajax({ | |
type: "POST", | |
url: $this.attr("action"), | |
// this submits the form to the same place as described | |
// in the form action attribute | |
data: $this.serialize(), | |
success: function(data, status) { | |
contact_form.find('.loading').hide(); | |
if (contact_form.find('.success').length <= 0) { | |
contact_form.append(Messages.thanks); | |
} else { | |
contact_form.find('.success').show(); | |
} | |
colorBox.resize(); | |
}, | |
error: function(xhr, status, error) { | |
contact_form.find('.loading').hide(); | |
if (contact_form.find('.ajax-error').length <= 0) { | |
contact_form.prepend(Messages.error); | |
} else { | |
contact_form.find('.ajax-error').show(); | |
} | |
// error message, probably bring the form back | |
$this.show(); | |
colorBox.resize(); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment