im using jquery to submit a php form. during the submission, it will validate for valid fields. so when user click the submit button, im expecting to show the loading gif while it process the form. when it is done, the loading gif fade off.
my jquery submit is as follows:
$(document).ready(function(){
$("#loadinggif").hide();
$(function(){
$("#form").submit(function(){
$.post("/postform.php", $("#form").serialize(),
function(data){
// Put an animated GIF image insight of content
$("#loadinggif").fadeIn().animate({ opacity: 1.0 },3000).fadeOut();
if(data.error != null){
$("#ajax_messagepost").html(data.error);
}
else{
var url = "/confirmation.php";
$(location).attr('href',url);
}
}, "json");
return false;
});
});
});
right now what happen is if the submit button is clicked, the loading gif shows and continue to show even after the data is returned. how do i hide it when data is returned??