How to send form data without page refresh?

前端 未结 4 718
清歌不尽
清歌不尽 2021-01-06 03:52

I have sending my data in ajax using submit button without any page refresh. But the page refreshed.

Please check my code and let me know the problem.



        
4条回答
  •  悲&欢浪女
    2021-01-06 04:22

    //Program a custom submit function for the form
    $("form#data").submit(function(event){
    
      //disable the default form submission
      event.preventDefault();
    
      //grab all form data  
      var formData = new FormData($(this)[0]);
    
      $.ajax({
        url: 'formprocessing.php',
        type: 'POST',
        data: formData,
        contentType: false,
        processData: false,
        success: function (returndata) {
          alert(returndata);
        }
      });
    
      return false;
    });
    

提交回复
热议问题