Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript fetch post form data

javascript fetch post form data with headers , in reactjs
--------------------------------
let formData = new FormData();
formData.append('data', 'formdata');
formData.append('data', 'formdata');

export const getData = async () => {
    await fetch('----url------', {
        method: 'POST',
        headers: {
            Authorization: 'Basic -------token----------',
        },
        body: formData
    }).then(response => response.json())
        .then(data => {
            console.log(data);
        })
}
Comment

Send Form Data Using Fetch

async function sendFormData()
 {

 const myData = document.getElementById("myData");
const formData = new FormData(myData);

	const obj= Object.fromEntries(formData);

const res = await fetch('/test', {method:'POST', body: JSON.stringify(obj), headers:{'Content-type': 'application/json; charset=UTF-8'}});
const response = await res.json();

console.log(response["a"]);

 }
Comment

Javascript Fetch FormData

fetch(form.action, {method:'post', body: new FormData(form)});
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery select element based on for attribute 
Javascript :: javascript regex replace all 
Javascript :: moment hour minute 
Javascript :: adminlte 3 toasts 
Javascript :: console log jquery 
Javascript :: call a function whenever routerlink is clicke angular 
Javascript :: event.preventDefault() in react hook 
Javascript :: convert csv to json python using pandas 
Javascript :: react lottie player on hover 
Javascript :: find in array of objects javascript 
Javascript :: jquery change value 
Javascript :: public class NameOf { public static String nameof<T(Expression<Func<T name) { MemberExpression expressionBody = (MemberExpression)name.Body; return expressionBody.Member.Name; } } 
Javascript :: angular An accessor cannot be declared in an ambient context. 
Javascript :: : not foundram Files/nodejs/npm: 3: 
Javascript :: prevent browser back button jquery 
Javascript :: date to seconds js 
Javascript :: Uncaught ReferenceError: axios is not defined 
Javascript :: remove all classes jquery 
Javascript :: jest global window object 
Javascript :: classlist add js to add more than one class 
Javascript :: show div js 
Javascript :: if checkbox is checked jquery 
Javascript :: template literal syntax not working 
Javascript :: jquery ajax endpoint 
Javascript :: add element to array using splice 
Javascript :: axios upload progress react 
Javascript :: mongoose connect to URL of atlas 
Javascript :: redirect javascript code 
Javascript :: node appendFile sync 
Javascript :: if variable does not exist javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =