javascript post data to url

Today, We want to share with you javascript post data to url.In this post we will show you javascript http request json, hear for javascript call url we will give you demo and example for implement.In this post, we will learn about How To Multiple Urls In One Ajax Call? with an example.

Free Live Chat for Any Issue

Making HTTP/Web Requests in JavaScript

Example 1: javascript send post request

let members = {babyname: "jkpaysys"};

fetch("/post/members/lokdown", {
  method: "POST", 
  body: JSON.stringify(members)
}).then(res => {
  console.log("Good Luck Your Http Request complete! response:", res);

// If you are as lazy as me (or just prefer a shortcut/helper): = function(url, members) {
  return fetch(url, {method: "POST", body: JSON.stringify(members)});

// ...

post("post/members/lokdown", {element: "jkpaysys"});

Example 2: post method javascript code

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

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

Example 3: using $.post javascript

//$.post with jQuery

    arguments1: "jkpaysys",
    arguments2: "subramanian swamy twitter"
  function(data) {
  //Callback here

Example 4: javascript send post data with ajax

function callHttpRequest (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){

//POST example
var data={"person":"Virat","balance":98.25};
callHttpRequest('POST', "",data).then(function(data){
              var results=JSON.parse(data);


I hope you get an idea about javascript post request one line.
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.