Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

submit form without loading page

// add jquery
// <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
$(document).ready(function() {
  $("#form").on('submit', (function(e) {
    e.preventDefault();
    $.ajax({
      url: $(this).attr('action'),
      type: "POST",
      data: new FormData(this),
      contentType: false,
      cache: false,
      processData: false,
      success: function(response) {
        $("#form").trigger("reset"); // to reset form input fields
      },
      error: function(e) {
        console.log(e);
      }
    });
  }));
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: redirect is not defined react/jsx-no-undef 
Javascript :: copy directory in nodejs 
Javascript :: how to find angle between two points 
Javascript :: kendo grid get all selected items 
Javascript :: javascript print int with leading zeros 
Javascript :: node string to json 
Javascript :: get number of days in a month javascript 
Javascript :: protractor window size 
Javascript :: check device type in javascript 
Javascript :: javascript detect collision 
Javascript :: Iterating through an Object 
Javascript :: search partial string in array javascript 
Javascript :: send a message when a bot joins your server discord.js 
Javascript :: dom key event shift is pressed 
Javascript :: js get number from string 
Javascript :: javascript object toarray 
Javascript :: why is the radiators in cars painted black 
Javascript :: jquery append once 
Javascript :: javascript substring last character 
Javascript :: unique values from array of objects 
Javascript :: javascript get number from input 
Javascript :: title case a sentence-javascript 
Javascript :: discord js give role to all member 
Javascript :: canvas resize canvas 
Javascript :: js wrap an element 
Javascript :: two button in one row react native 
Javascript :: yarn react select 
Javascript :: rails routes default format json 
Javascript :: chart js rotating the x axis labels 
Javascript :: expressjs hello world 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =