I'm making a sign up system. After user successfully sign up, form->ajax->php, ajax adds html to a premade empty message div.
$("#register_form").submit(function(event) {
var $data = $(this).serialize();
var result = "";
$.ajax({
cache : false,
type : "POST",
url : "php/register.php",
data : $data,
success : function(response) {
if(response === "OK"){
result = "<div class='alert alert-success'>You have successfully registered!<br/>";
result += "Please check your mailbox for the activation link. It may take a few minutes.<br/>";
result += "<a id='resend'>Resend Confirmation Email</a>";
result += "</div>";
$("#register_form").slideUp(500);
}
else{
result = '<div class="alert alert-danger">' + response + '</div>';
}
$("#register_response").html(result);
$("#register_response").slideDown(500);
}
});
event.preventDefault();
});
I put the 'resend confirmation email' in there, just an empty link waiting to be clicked on. But it seems the sign up page's javascript (which is the same file the above script is in, I did $("#resend").click(...)
) doesn't apply to it. Where do I put the javascript so that this will work?
Also, if this is not a good way to add html using javascript, what's a good way to achieve this?