Search code examples
javascriptajaxjqueryjquery-post

jquery $.post explain


I wrote the following code to post data with jQuery, It's working fine, but without return false;, the code didn't work, I found this return statement after 1 full day of searching...

Could somebody please tell me, what is the use of return false; after the end of $.post?
I am a newbie in jQuery and would like to get a better understanding of this.

$("#formid").submit( function () {    
  $.post(
   'ajax.php',
    $(this).serialize(),
    function(data){                 
       $("#result").html(data);
       $("#result").fadeIn('slow');
    }
  );
  return false;   
}); 

Solution

  • The return false; here is not used for $.post method of AJAX instead it is used to prevent the form(#formid) submission which can cancel your AJAX request