Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

send form data to endpoint js

// Hookbin is a free service that enables you to collect, parse, and view HTTP requests.
// Create your unique endpoints to inspect headers, body, query strings, cookies, uploaded files, and much more.
// https://hookbin.com/

// Your hookbin URL goes here:
const url = "";
      const formEl = document.querySelector("form");
      formEl.addEventListener("submit", async (e) => {
        e.preventDefault();
        const formData = new FormData(formEl);
        const formDataSerialized = Object.fromEntries(formData);
        const jsonObject = {
          ...formDataSerialized,
          sendToSelf: formDataSerialized.sendToSelf ? true : false,
        };
        try {
          const response = await fetch(url, {
            method: "POST",
            body: JSON.stringify(jsonObject),
            headers: {
              "Content-Type": "application/json",
            },
          });
          const json = await response.json();
          console.log(json);
        } catch (e) {
          console.error(e);
          alert("there as an error");
        }
      });
Comment

PREVIOUS NEXT
Code Example
Javascript :: Using Fetched Data With Backbone 
Javascript :: auto load window on change viewport react 
Javascript :: climbing stairs 
Javascript :: clear an array 
Javascript :: quill js laravel 
Javascript :: how to add picture to picture video js in old library in js 
Javascript :: Solution-4-B--solution options for reverse bits algorithm js 
Javascript :: how to get event from iframe 
Javascript :: javascript odd or even 
Javascript :: copy array 
Javascript :: callback function jquery 
Javascript :: regexp object 
Javascript :: onhover 
Javascript :: what is callback hell in javascript 
Javascript :: splice en javascript 
Javascript :: open json javascript 
Javascript :: for-of loop 
Javascript :: instance in javascript 
Javascript :: how to convert roman to decimal in javascript 
Javascript :: check for null 
Javascript :: javascript type 
Javascript :: javascript + Operator with Numbers 
Javascript :: javascript for...of with Maps 
Javascript :: JavaScript Object Prototypes 
Javascript :: jQuery - Dimensions 
Javascript :: cannot set headers after they are sent to the client mongoose 
Javascript :: change xy scale phaser 
Javascript :: phaser create animation from texture atlas 
Javascript :: scrolling text animation javascript 
Javascript :: polygon intersection js 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =