Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get form response with javascript

document.forms['myFormId'].addEventListener('submit', (event) => {
    event.preventDefault();
    // TODO do something here to show user that form is being submitted
    fetch(event.target.action, {
        method: 'POST',
        body: new URLSearchParams(new FormData(event.target)) // event.target is the form
    }).then((resp) => {
        return resp.json(); // or resp.text() or whatever the server sends
    }).then((body) => {
        // TODO handle body
    }).catch((error) => {
        // TODO handle error
    });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: componentdidmount hooks 
Javascript :: dotenv jest 
Javascript :: jquery get first character of string 
Javascript :: firebase database check if value exists 
Javascript :: how to ask input in javascript 
Javascript :: javascript string to int 
Javascript :: prime factorization javascript 
Javascript :: js get alphabet as array 
Javascript :: jquery loop through list elements 
Javascript :: jquery only on mobile 
Javascript :: check if string is valid json dart 
Javascript :: regex 24 hour time validation regex 
Javascript :: angular material change placeholder color 
Javascript :: preg_replace javascript 
Javascript :: MIN_SAFE_INTEGER 
Javascript :: nodefetch of ES modules is not supported. 
Javascript :: js is letter 
Javascript :: scrolltop top to bottom body get count 
Javascript :: react native port 
Javascript :: input type number react native 
Javascript :: nodemail self signed certificate in certificate chain 
Javascript :: javascript add string to middle of string 
Javascript :: get selected text js 
Javascript :: how to print to console javascript 
Javascript :: js function return fetch result 
Javascript :: alert confirm prompt javascript 
Javascript :: js mouse enter 
Javascript :: reaact native expo jsx 
Javascript :: document queryselector click event 
Javascript :: ajax error get output 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =