Ajax show div if variable is set
So I'm using jQ开发者_如何学Pythonuery to POST some items and save into the database. I have two optional fields, if they're not empty, I'd like to fadeIn in a related div in the success function. You'll notice the #picCheck.fadeIn
. Right now that fades in if the stuff is submitted, but like I said, I'd like for it fadeIn only if the variable picvault
from the submitted form has is set.
Here's the jQuery:
$.ajax({
type: "POST",
url: "edit.php",
data: $form.serialize(),
success: function(){
$('form#editForm').hide();
$('div.success').center();
$('div.success').fadeIn('slow').animate({opacity: 1.0}, 2000).fadeOut(1000);
$('#picCheck'+sid).fadeIn('slow');
}
}); // End .ajax function
Simply check the value of picvault in your callback function (assuming it's a checkbox)
if($("#picvault").is(":checked")) {
$('#picCheck'+sid).fadeIn('slow');
}
If you have access to the form, just put an if statement around your fadeIn code checking that value.
精彩评论