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

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

/**
 * 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 :: bootstrap show modal jquery 
Javascript :: remove extra space in string javascript 
Javascript :: jquery submit form on enter 
Javascript :: javascript get current month start and end date 
Javascript :: change display javascript 
Javascript :: javascript get element height 
Javascript :: count child elements javascript 
Javascript :: Extract number from string javascripy 
Javascript :: javascript scroll to element 
Javascript :: js random number between 1 and 100 
Javascript :: javascript check if string is json parsable 
Javascript :: jquery cdn cloudflare 
Javascript :: javascript can you defer inline 
Javascript :: get text selected option jquery 
Javascript :: javascript array includes another array 
Javascript :: kill node 
Javascript :: manage favicon with express app 
Javascript :: how to change background image using javascript 
Javascript :: how to remove the parent div from the child in jquery 
Javascript :: javascript get random floating number 
Javascript :: react native touchableopacity disable 
Javascript :: styling scrollview height in react native 
Javascript :: react fetch post 
Javascript :: js remove the last character of a string 
Javascript :: Could not find com.yqritc:android-scalablevideoview:1.0.4 react native video 
Javascript :: css customize console.log 
Javascript :: laravel ajax post request 
Javascript :: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. 
Javascript :: ejs comments 
Javascript :: google sheets get sheet by name 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =