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

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 :: passing data variable using ajax 
Javascript :: Ts get first string char 
Javascript :: get all the properties of a object in javascript 
Javascript :: react image compression 
Javascript :: ajax uploading progress 
Javascript :: javascript xmldocument to string 
Javascript :: PG::DuplicateTable: ERROR: relation already exists 
Javascript :: make select option selected javascript 
Javascript :: console log object js 
Javascript :: elevation react native 
Javascript :: nestjs return error response 
Javascript :: why does my page reloads on form submission 
Javascript :: Error: `createStackNavigator()` has been moved to `react-navigation-stack`. 
Javascript :: adding media queries in makeStyle material react 
Javascript :: adding new sass version 
Javascript :: set background opacity react native 
Javascript :: vue dev server proxy not working 
Javascript :: javascript every other element in array 
Javascript :: keypress javascript 
Javascript :: react native socket io 
Javascript :: how to remove special characters from a string in javascript using regex 
Javascript :: load +main.js with system.import 
Javascript :: xhr 
Javascript :: pdf table files download react not working 
Javascript :: javascript format number with K M 
Javascript :: run cypress 
Javascript :: javascript ES6 destructure dynamic property name 
Javascript :: js desktop notification 
Javascript :: how do i make a link to direct me to a new page when i click on a button in react 
Javascript :: convert date to millisecond in javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =