Last active
November 1, 2017 11:57
-
-
Save agustinprosperi/60944fa4ca8a76bba01c to your computer and use it in GitHub Desktop.
jquery short examples
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
// wait for images to load | |
$(window).bind("load", function() { | |
// code here, masonry for example | |
}); | |
// validateEmail | |
function validateEmail(email) { | |
var re = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; | |
return re.test(email); | |
} | |
// Ajax call | |
$(".register-form").submit(function(e){ | |
if( $(currentFormId).hasClass("sending") ) return false; | |
//if no sending yet, send | |
e.preventDefault(); | |
currentFormId = '#'+$(this).attr("id"); | |
var formData = $(this).serialize(); | |
$(currentFormId).addClass("sending"); | |
$.ajax({ | |
type: 'POST', | |
url: ajax_object.ajax_url, | |
data: formData, | |
success: function(data, textStatus, jqXHR){ | |
var $messagebox = $(currentFormId).find(".form_messages"); | |
$messagebox.hide(); | |
if(data.status == 'success'){ | |
$messagebox.html( data.message ); | |
$(currentFormId)[0].reset(); | |
}else if(data.status == 'error'){ | |
$messagebox.html( data.message ); | |
}else{ | |
$messagebox.html( $(".tecnical_error").first().html() ); | |
} | |
$messagebox.slideDown(300); | |
$(currentFormId).removeClass("sending"); | |
}, | |
error: function(jqXHR, textStatus, errorThrown){ | |
var $messagebox = $(currentFormId).find(".form_messages"); | |
$messagebox.hide(); | |
$messagebox.html( $(".tecnical_error").first().html() ); | |
$messagebox.slideDown(300); | |
$(currentFormId).removeClass("sending"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment