Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 :: post request with data and headers 
Javascript :: jquery datepicker 
Javascript :: convert string to camelcase 
Javascript :: clear all cookies 
Javascript :: how to push key value pair to object javascript 
Javascript :: get react form input data, How get form input data in react 
Javascript :: how to install nuxtjs with tailwind css 
Javascript :: javascript get current window location without parameters 
Javascript :: js detect if content editable div is empty 
Javascript :: Add Image For React Native 
Javascript :: uncheck multiple checkboxes javascript 
Javascript :: check valid Phonenumbers 
Javascript :: expres body parser 
Javascript :: getting values for metaboxes in wordpress 
Javascript :: react native refresh flatlist on swipe down 
Javascript :: for in range javascript 
Javascript :: fs fstat 
Javascript :: get attribute js 
Javascript :: java script strict tag 
Javascript :: js loop 
Javascript :: .foreach in javascript 
Javascript :: select the first elemnt have class in jquery 
Javascript :: how to get circle around text in react natvie 
Javascript :: how to make page scroll to the top jsx 
Javascript :: js how to calculate factorial 
Javascript :: javascript uppercase function 
Javascript :: change li position in ul jquery 
Javascript :: datatable table header not responsive 
Javascript :: javascript sleep 3 second 
Javascript :: count in string javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =