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

javascript send post

var xhr = new XMLHttpRequest();
xhr.open("POST", yourUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
    value: value
}));
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

post requests javascript

xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xhr.send(someStuff);
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 :: how to focus out of an input in testing library 
Javascript :: Node.js (node 11.12.0) sample 
Javascript :: javascript timer countdown with seconds 59 
Javascript :: upload text file react js functional component 
Javascript :: how to convert string to random case in javascript 
Javascript :: react native file pdf to base64 
Javascript :: rem api rest 
Javascript :: javascript DOM SELECT 
Javascript :: findPotentialLikes javascript 
Javascript :: javascript Non-numeric String Results to NaN 
Javascript :: clear input field react 
Javascript :: javascript Symbols are not included in for...in Loop 
Javascript :: javascript WeakMaps Are Not iterable 
Javascript :: freecodecamp javascript basic step quoting string 
Javascript :: javaScript values() Method 
Javascript :: ejs split string 
Javascript :: nodjs : Stream for big file 
Javascript :: How to export functions and import them in js 
Javascript :: get page scrolling amount js 
Javascript :: phaser increment x layers 
Javascript :: phaser mixed animation 
Javascript :: refresh secounds 
Javascript :: white for file loaded 
Javascript :: nodejs: send html file to show in Browser 
Javascript :: Set A Function For An Element 
Javascript :: js function expression 
Javascript :: javascript trunc 
Javascript :: if else javascript 
Javascript :: asp net core use newtonsoft json 
Javascript :: rest parameters javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =