Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

submit form without redirection

function formSubmit(event) {
   var url = "/post/url/here";
   var request = new XMLHttpRequest();
   request.open('POST', url, true);
   request.onload = function() { // request successful
      // we can use server response to our request now
      console.log(request.responseText);
   };

   request.onerror = function() {
      // request failed
   };

   request.send(new FormData(event.target)); // create FormData from form that triggered event
   event.preventDefault();
}

// and you can attach form submit event like this for example
function attachFormSubmitEvent(formId) {
   document.getElementById(formId).addEventListener("submit", formSubmit);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: for loop array 
Javascript :: get input js 
Javascript :: eslint disable next line multiple rules 
Javascript :: try...catch...throw javascript 
Javascript :: how to set window location search without reload 
Javascript :: es6 functions 
Javascript :: bootstrap searchable pagination table example jquery 
Javascript :: format json command line 
Javascript :: route parameter in node 
Javascript :: how to add lang attribute in next js 
Javascript :: forceupdate usereducer 
Javascript :: react native showing double header stack and drawer menu 
Javascript :: binary search javascript 
Javascript :: javascript selector second element nth child element 
Javascript :: selector jquery 
Javascript :: html canvas not clearing 
Javascript :: async foreach 
Javascript :: vuejs transform observer to object 
Javascript :: js add class to html 
Javascript :: javascript array read object value in array 
Javascript :: node assert 
Javascript :: vue js use component everywhere 
Javascript :: javascript int to string 
Javascript :: Flatten a multidimension array 
Javascript :: do somthing after page completly load jqery 
Javascript :: ternary operator jquery 
Javascript :: Find the index of an item in the Array 
Javascript :: react router remove location state on refresh 
Javascript :: command to start a new react app using vite 
Javascript :: getting te value of select multiple value 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =