1

I've seen many stack overflow posts telling the user to prevent the page refresh by using return false or by changing the input type to button, but this works by disabling submission, which I need. How do I keep submission of my form enabled using my button, without refreshing the page upon use?

EDIT: this post is entirely different from the supposed duplicate. That post is is only concerned with submission of the form, whereas the crux of this post is submission without page refresh

Rik Johnson
  • 111
  • 11

1 Answers1

1

you can submit a form using the .submit() function in jquery

$('#your-id-form').submit( function(e) { 
   //prevent submit
   e.preventDefault(); //Thx @alex

   //do things on submit
   $.ajax({
       data: "data",
       type: "POST",
       url: "your-destiny.php",
       beforeSend: function(){
        //before send data
       },
       success: function(data){
           // the data
           console.log(data);
       }
   });
 });

Cheers,

Roy Bogado
  • 4,299
  • 1
  • 15
  • 31