javascript - jQuery form submission is returning false instead of waiting for server response -


i have jquery form sends data server after validating. server sends response , site processes returned information. here's javascript in question:

$("#signup").on('submit', function(e){           var isvalidate = $("#signup").valid();           if(isvalidate)           {             var json =  $('#signup').serialize();              var theemail = $('#signup #inputemail').val();              //hide step 1 modal             $('#steponesignup').modal('hide');              //open processing modal             $('#processingmodal').modal();              $.post('http://localhost:5000/agm/savenewuser/', json, function( data ) {               alert('returned data');               if(data === "success"){                 //hide processing modal                 $('#processingmodal').modal('hide');                }else if(data === "userexists"){                 $('#processingmodal').modal('hide');                 $('#duplicateemail').modal();               }             });           }else{             return false;           }       }); 

i can see in server log $.post(http://localhost...) posting fine. server processing form information (which takes couple of seconds) before gets chance send response form redirects browser to:

http://localhost:8888/?firtname=whateverinfoiputintheform&lastname=yeahyeahyeah 

i never alert('returned data');.

any idea what's going on here?

you should return false, in case, prevent default post-back:

$("#signup").on('submit', function(e){     var isvalidate = $("#signup").valid();     if(isvalidate)     {         ...     }     return false; }); 

it causing ajax post request can not process it's response because default post-back causes before ajax post's response received.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -