javascript - Loading gif while form.submit() -


i have js on button class="submit" :

$( ".submit" ).click(function( event ) {          if(some checks){             ...         }else{             $("#importform").submit(function(event){                 alert("submitted");             });         }     }); 

but form never submited, , alert never pop. if drop

function(event){   alert("submitted"); } 

it's working well. idea?

edit :

actually want display loading gif while form submited, load() in view :

$("body").load(url, function(){    $('#loadinggif').empty(); });       $('#loadinggif').empty().html('<img src="/assets/image/loader.gif" width=31 height=31 alt="loading image" />');  

this piece of code:

$("#importform").submit(function(event){     alert("submitted"); }); 

adds event listener element (presumably <form>), doesn't call it. if .submit not button within form should change to:

$( ".submit" ).click(function( event ) {      if(some checks){         ...     }else{         $("#importform").submit(function(event){ // add event listener             alert("submitted");         }).submit(); // submit form     } }); 

http://jsfiddle.net/2yz6a9l5/1/

answer edit : you'd have send form data using ajax, because submitting form standard way makes new request, current page unloads , browser waits response server, means there's no place display gif.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -