Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js post

let data = {element: "barium"};

fetch("/post/data/here", {
  method: "POST",
  headers: {'Content-Type': 'application/json'}, 
  body: JSON.stringify(data)
}).then(res => {
  console.log("Request complete! response:", res);
});
Comment

post request javascript

const createPostRequest = async () => {
	try{
		const { data } = await axios.post(url, body_data, {
		   headers: {
	    	 'Authorization': `Basic ${token}`
		   },
		})
    
	    console.log(data)
	} catch (error) {
		console.log(error)
	}
}

createPostRequest();
Comment

post method in javascript

function createNewProfile(profile) {
    const formData = new FormData();
    formData.append('first_name', profile.firstName);
    formData.append('last_name', profile.lastName);
    formData.append('email', profile.email);

    return fetch('http://example.com/api/v1/registration', {
        method: 'POST',
        body: formData
    }).then(response => response.json())
}

createNewProfile(profile)
   .then((json) => {
       // handle success
    })
   .catch(error => error);
Comment

javascript post request

const url = "http://example.com";
fetch(url, {
    method : "POST",
    body: new FormData(document.getElementById("inputform")),
    // -- or --
    // body : JSON.stringify({
        // user : document.getElementById('user').value,
        // ...
    // })
}).then(
    response => response.text() // .json(), etc.
    // same as function(response) {return response.text();}
).then(
    html => console.log(html)
);
 Run code snippet
Comment

javascript post

/**
 * sends a request to the specified url from a form. this will change the window location.
 * @param {string} path the path to send the post request to
 * @param {object} params the parameters to add to the url
 * @param {string} [method=post] the method to use on the form
 */

function post(path, params, method='post') {

  // The rest of this code assumes you are not using a library.
  // It can be made less verbose if you use one.
  const form = document.createElement('form');
  form.method = method;
  form.action = path;

  for (const key in params) {
    if (params.hasOwnProperty(key)) {
      const hiddenField = document.createElement('input');
      hiddenField.type = 'hidden';
      hiddenField.name = key;
      hiddenField.value = params[key];

      form.appendChild(hiddenField);
    }
  }

  document.body.appendChild(form);
  form.submit();
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: write hello world in javaskript 
Javascript :: Split string on the first white space occurrence 
Javascript :: chrome storage local update 
Javascript :: atoi javascript 
Javascript :: js event handlers 
Javascript :: select option in js dynamically 
Javascript :: js string insert space 
Javascript :: angular chartjs align legend left 
Javascript :: ForEach Element with Function or Lambda 
Javascript :: count duplicate array javascript 
Javascript :: cookie-session use in node 
Javascript :: javascript call and apply methods 
Javascript :: moment js date between two dates 
Javascript :: chrome extension contextmenus 
Javascript :: javascript parseInt() method 
Javascript :: updatedAt mongoose stop 
Javascript :: click binding angular 8 
Javascript :: Jest DOM Manipulation 
Javascript :: how to upload react js project on server 
Javascript :: react hook form example stack overflow 
Javascript :: javascript copy clipboard 
Javascript :: vuejs get data fromo ajax 
Javascript :: turn off js console 
Javascript :: how to add class in javascript dynamically 
Javascript :: jquery properly work 
Javascript :: how to use cros 
Javascript :: production server next.js 
Javascript :: The document.createElement() Method 
Javascript :: send response from iframe to parent 
Javascript :: has class in jquery 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =