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 javascript

//$.post with jQuery

$.post(
  "path/to/your/php/file", 
  {
    param1: "Value",
    param2: "Value"
},
  function(data) {
  //Callback here
  }
);
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 :: array with unique values javascript 
Javascript :: what does document.getelementbyid return 
Javascript :: unix to time in javascript 
Javascript :: javascript primitive data types 
Javascript :: for loop array 
Javascript :: change on select with javascript 
Javascript :: usestate react 
Javascript :: es6 functions 
Javascript :: jquery if element appears 
Javascript :: process return value 
Javascript :: javaScript setMinutes() Method 
Javascript :: Uncaught (in promise) cancel 
Javascript :: live search javascript 
Javascript :: react component will mount new method 
Javascript :: javascript if statement 
Javascript :: logic operators in js 
Javascript :: completablefuture async example 
Javascript :: react build blank page 
Javascript :: obtener ancho de pantalla javascript 
Javascript :: array.slice 
Javascript :: react style css image 
Javascript :: incoroporate js and css file in html 
Javascript :: javascript Using splice() to Remove Elements 
Javascript :: How to Display a List in React 
Javascript :: javascript to camelcase 
Javascript :: disabled text color tailwind 
Javascript :: JavaScript try...catch in setTimeout 
Javascript :: get date from datepicker 
Javascript :: aes 256 file encryption node js 
Javascript :: object find key javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =