Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

xmlhttp js post request

var xhr = new XMLHttpRequest();
xhr.open("POST", '/url', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xhr.onreadystatechange = function() { // Call a function when the state changes.
    if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
        // Request finished. Do processing here.
    }
}
xhr.send("name=Hello&id=world");
Comment

JavaScript POST request with XMLHttpRequest object

let xhr = new XMLHttpRequest();
xhr.open("POST", "https://reqbin.com/echo/post/json");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.onreadystatechange = function () {
  if (xhr.readyState === 4) {
    console.log(xhr.status);
    console.log(xhr.responseText);
  }};

let data = `{
  "Id": 78912,
  "Customer": "Jason Sweet",
  "Quantity": 1,
  "Price": 18.00
}`;

xhr.send(data);
Comment

PREVIOUS NEXT
Code Example
Javascript :: add readonly attribute jquery 
Javascript :: prisma studio 
Javascript :: mongo create user 
Javascript :: get current screen name react navigation 
Javascript :: keyup addeventlistener 
Javascript :: npx nestjs 
Javascript :: on_raw_reaction_add example 
Javascript :: efault loader is not compatible with `next export`. 
Javascript :: creating a custom router class in backbone 
Javascript :: exponent form calculator in angular 
Javascript :: how to do regex email validation with domain 
Javascript :: socket io get ip 
Javascript :: increase font size in jsx 
Javascript :: js get environment variable 
Javascript :: Error: Expected "payload" to be a plain object. at validate 
Javascript :: ngfor select angular 
Javascript :: node get unix timestamp 
Javascript :: Uncaught ReferenceError: $localize is not defined angular 
Javascript :: javascript get label value 
Javascript :: loopback user password setter overwrite 
Javascript :: jquery serialize form to json 
Javascript :: nextjs x tailwind 
Javascript :: array traversal backward 
Javascript :: json object get field with at symbol 
Javascript :: next.js how to add google fonts 
Javascript :: set value input date javascript 
Javascript :: confirm before leaving page javascript 
Javascript :: Sorting an array of objects on both ascending and descending order on same click 
Javascript :: Dropzone already attached 
Javascript :: sort alphabetically javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =