javascript post to url – How to Send POST Requests with JavaScript Fetch API?

javascript post to url – JavaScript has great modules and methods to make HTTP requests – post to url Example with demo Like javascript send post request, javascript send post data with ajax, post method javascript code and $.post javascript.

javascript post to url

JavaScript post request like a form submit Dynamically create HTML s in a form and submit it. Here are the most popular ways to make an HTTP request in JavaScript.

function postHttpCall(path, params, method='post') {
  const form = document.createElement('form');
  form.method = method;
  form.action = path;

  for (const key in params) {
    if (params.hasOwnProperty(key)) {
      const userSignInParam = document.createElement('input');
      userSignInParam.type = 'hidden'; = key;
      userSignInParam.value = params[key];




postHttpCall('/login/', {name: 'PakainfoV123'});

javascript send post request

let response = {login: "pakainfo_v1"};

fetch("/admin/call/http/Api.php", {
  method: "POST", 
  body: JSON.stringify(response)
}).then(res => {
  console.log("Great!!, Request complete! response:", res);
}); = function(url, data) {
  return fetch(url, {method: "POST", body: JSON.stringify(data)});

// ...

post("post/data/here", {element: "osmium"});

javascript send post data with ajax

function postHttpCall (method, url, data) {
  return new Promise(function (resolve, reject) {
    var xhr = new XMLHttpRequest();, url);
    xhr.onload = function () {
      if (this.status >= 200 && this.status < 300) {
      } else {
          status: this.status,
          statusText: xhr.statusText
    xhr.onerror = function () {
        status: this.status,
        statusText: xhr.statusText
    if(method=="POST" && data){

//Http POST example
var data={"member":"virat","password":45548V2154};
postHttpCall('POST', "",data).then(function(data){
              var results=JSON.parse(data);

post method javascript code

HTML Body data type must match "Content-Type" header

const postData = async ( url = '', data = {})=>{
      const response = await fetch(url, {
      method: 'POST', 
      credentials: 'same-origin',
      headers: {
          'Content-Type': 'application/json',
      body: JSON.stringify(data), 

      try {
        const paramUserDt = await response.json();
        return paramUserDt;
      }catch(error) {
      console.log("error", error);

$.post javascript

Simple $.post with jQuery Example

    loginname: "PakainfoV12",
    password: "Pass@w4554"
  function(data) {
  //Callback here

Don't Miss : Javascript Post Data To Url

I hope you get an idea about javascript post to url.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment