showing results for - "javascript post request"
Joshua
08 Feb 2016
1let data = {element: "barium"};
2
3fetch("/post/data/here", {
4  method: "POST", 
5  body: JSON.stringify(data)
6}).then(res => {
7  console.log("Request complete! response:", res);
8});
9
10
11// If you are as lazy as me (or just prefer a shortcut/helper):
12
13window.post = function(url, data) {
14  return fetch(url, {method: "POST", body: JSON.stringify(data)});
15}
16
17// ...
18
19post("post/data/here", {element: "osmium"});
20
Joshua
03 Oct 2019
1var xhr = new XMLHttpRequest();
2xhr.open("POST", yourUrl, true);
3xhr.setRequestHeader('Content-Type', 'application/json');
4xhr.send(JSON.stringify({
5    value: value
6}));
Habiba
23 Jul 2017
1function makeRequest (method, url, data) {
2  return new Promise(function (resolve, reject) {
3    var xhr = new XMLHttpRequest();
4    xhr.open(method, url);
5    xhr.onload = function () {
6      if (this.status >= 200 && this.status < 300) {
7        resolve(xhr.response);
8      } else {
9        reject({
10          status: this.status,
11          statusText: xhr.statusText
12        });
13      }
14    };
15    xhr.onerror = function () {
16      reject({
17        status: this.status,
18        statusText: xhr.statusText
19      });
20    };
21    if(method=="POST" && data){
22        xhr.send(data);
23    }else{
24        xhr.send();
25    }
26  });
27}
28
29//POST example
30var data={"person":"john","balance":1.23};
31makeRequest('POST', "https://www.codegrepper.com/endpoint.php?param1=yoyoma",data).then(function(data){
32              var results=JSON.parse(data);
33});
Niko
28 May 2019
1const postData = async ( url = '', data = {})=>{
2    console.log(data);
3      const response = await fetch(url, {
4      method: 'POST', 
5      credentials: 'same-origin',
6      headers: {
7          'Content-Type': 'application/json',
8      },
9     // Body data type must match "Content-Type" header        
10      body: JSON.stringify(data), 
11    });
12
13      try {
14        const newData = await response.json();
15        console.log(newData);
16        return newData;
17      }catch(error) {
18      console.log("error", error);
19      }
20  }
21
Javier
30 May 2019
1<!DOCTYPE html>
2<html>
3  <head>
4    <meta charset="UTF-8">
5    <meta http-equiv="X-UA-Compatible" content="IE=edge">
6    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7    <link rel="stylesheet" href="assets/style.css">
8    <!-- <script src="assets/javascript.js"></script> -->
9    <title>Telegramga habar jo`natish</title>
10  </head>
11  <body>
12    <div class="contaakb">
13      <h2>Telegramga habar yozish</h2>
14      <p>Guruhlarga habar yozish uchun qilingan modul</p>
15    </div>
16    <div class="container">
17      <form action="?" method="post">
18        <div class="row">
19          <div class="col-25">
20            <label for="fname">Guruh nomi</label>
21          </div>
22          <div class="col-75">
23            <input type="text" id="group" name="group" placeholder="Telegram guruhning nomini yozing" value="" autofocus>
24          </div>
25        </div>
26        <div class="row">
27          <div class="col-25">
28            <label for="country">Guruh (ixtiyoriy)</label>
29          </div>
30          <div class="col-75">
31            <select id="select" name="select" onchange="getComboA(this)">
32              <option selected value="tanlang">Tanlang</option>
33              <option value="ITspeciallessons2">Qobiljon</option>
34              <option value="ITspeciallessons1">Azizbek</option>
35              <option value="taxiuchqorgontoshkent">Uchqorgon Toshkent TAXI</option>
36              <option value="clashuzhackersw">ClashUzHackerSW</option>
37              <option value="nodirjonbotirov">Nodirjon ISh</option>
38            </select>
39          </div>
40        </div>
41        <div class="row">
42          <div class="col-25">
43            <label for="subject">Habar matni</label>
44          </div>
45          <div class="col-75">
46            <textarea id="message" name="message" placeholder="Habar matnini yozing" style="height:200px" autofocus></textarea>
47          </div>
48        </div>
49        <div class="row">
50          <button type="submit" onclick="loadDoc(event)">
51          Jo'natish
52          </button>
53        </div>
54      </form>
55    </div>
56    <script type="text/javascript">
57      function getComboA(selectObject) {
58          document.getElementById("group").disabled = true;
59          document.getElementById("message").focus();
60          console.log('group disabled');
61      }
62      
63      function loadDoc(event) {
64          document.getElementById("message").disabled = true;
65          document.getElementById("select").disabled = true;
66          document.getElementById("group").disabled = true;
67          
68          var params = 'message='+document.getElementById('message').value+'&select='+document.getElementById('select').value+'&group='+document.getElementById('group').value+'&ajax=yes';
69          var xhttp = new XMLHttpRequest();
70          xhttp.open("POST", "?", true);
71          xhttp.onreadystatechange = function() {
72              if (this.readyState == 4 && this.status == 200) {
73                document.getElementById("demo").innerHTML = this.responseText;
74              }
75            };
76          xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
77          xhttp.onreadystatechange = function() {//Call a function when the state changes.
78                  if(xhttp.readyState == 4 && xhttp.status == 200) {
79                      alert(xhttp.responseText);
80                      document.getElementById("message").disabled = false;
81                      document.getElementById("select").disabled = false;
82                      document.getElementById("group").disabled = false;
83                  }
84              }
85            xhttp.send(params);
86           event.preventDefault();
87      }
88    </script>
89  </body>
90</html>
91
Diane
21 Apr 2016
1const Http = new XMLHttpRequest();
2const url='https://jsonplaceholder.typicode.com/posts';
3Http.open("GET", url);
4Http.send();
5
6Http.onreadystatechange = (e) => {
7  console.log(Http.responseText)
8}
queries leading to this page
post methode jshow to make a function in js with postjs request postajax javascript postpost request from jshow to do a post request javascriptjs post request examplejs post functionjs make a post requestjavascript post request examplepost request in jssimple javascript post requestpost data in javascriptcreate post jsxmlhttp post requestjavascript send get requestpost request using request in javascriptjavascript send post request in consolesend post data jssample post request javascriptjavascript http postjs http post requestpost form value jspost javascript w3schoolshow to send post request jsjavascript http requestcall post from javascriptjs send post request with bodysend data with jquery ajax post node jsjs send post web requestform post javascriptmake a post request javascriptpost request in plain javascriptform submit and post req in javascripttrigger 24post javascriptmake post request in javascriptsend post request with only javascripthow to send post request in javascriptjavascript post formjavascript request postpost request in javascripthow to send a post request in javascriptsending post request in javascriptjavascript sent in posthow to post http request in javascripthttp request js postsent post request javascripthow to post using jssend post request from javascriptjava script post requestjavascrpt post requestsending a post request javascriptjavascript send post datapost jssend post via javascripthow to make a post request jssend form data in post request javascriptpost in javascripthow to make post request in javascriptmethod post in javascriptmake post from javascriptsend values with post ajaxpost methodhtml post javascriptpost function in javascriptjs make post requesthtml js make post request with bodyhtml javascript send post requestjavascript post examplejs post requestrcreate post request javascriptsending a post request jspost js examplerequest post javascriptajax post request javascript from form datasend post api jsjavascript post responsesend post request javascript from browserhow to request method post jsjavascript http post requestjavascript http request postxhttp post requestjavascript make a postjavascript ajax post data examplepost method from javascripthow to send post request with javascriptxmlhttprequest post js send post request urlhow to make post request with javascriptjavascript do http post requesthow to post request in javascriptjavascript postpost req jsmake post request javascriptjavascript make post requestpost request html javascripthow to code if a website post jsjava script do post datapost form with javascripthow to do a post request using javascriptjs post formpost method jssend a post request in jssend ajax post request javascriptjs send post requesthow to make post action in javascriptpost request from html form using jspost on javascriptjavascript html postjavascript send post requestnew xmlhttprequest post examplepost method javascriptpost method in javascriptajax post data url in jssend post request with form data javascriptsend post calls using jspost data to url using ajax how to make a post request in javascripthtml js post requestrequest open in javascriptsend post request form javascriptsend string in post request javascripthttp request post method javascriptjs sent post requestrsend post request with javascripthttp post request javascripthow to make post request javascripthow to send post request in jshandle post request form javascriptsend a post request jshow to send ajax request with jsxhttp post javascriptsend data request javascriptsend post request using javascriptjs request post examplejs post requestjavascript post to urlhttp post method javascriptjavascript post form datahow to send a post request jssend data with jquery ajax post nodejshtml script post methodsend post request in jsjs http request postjavascript send post request jsonhttp post request example javascripthow to use post request in javascriptpost request jsjs postjavascript send http post requestsend simple post form javascriptrequest open 28 post url true 29how to make a javascript post requestpost request javascriptjs post datause javascript to post datahttp post request javascript examplesending a post request in javascriptsend post request javascriptpost request javascripmake post request with javascriptsubmit post request javascriptjavascript post requestspost call in javascriptsend post request to server javascriptpost using javascriptmethod post jssend post request in javascriptpost request using jsjavascript post functionjavacsript postjs send post messagesend a post request from javascriptsend post request with parameters javascripthow to post in javascriptpost request jspost via javascriptpost request with jsjavascript post request bosyhttp post request jsxmlhttprequest javascript example post examplehow to make a post request javascripthow to send post request to a url in javascriptjavascript to send post requestjavascript post request responsejavascript post rerquestpost request on jsjavascript send post formpost javascriptpost in jsjavascript send xhr requestpost in html jsform method post inside jsxhttpsend post request jsjavasciprt post requesthow to use post method in javascriptmake javascript post requestjava script post callrequest post for javascripthtml js how to postjavascript send http post send data in post request javascriptjavascript ajax postpost request via jsmake post request html javascriptpost from javascriptsend post jspost with javascriptsend a post request javascriptjavascript httprequest postpost jquerycreate form post request javascriptpost data jsjavascript making post requestjavascript send posthow to do a post method in javascripthow to make a post request in jspost method request javascriptjavascript post requesthow to post request from javascriptjavascript post request