Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //boilerplate code for an AJAX POST request using an XMLHttpRequest object.
- const xhr = new XMLHttpRequest();
- const url = 'https://api-to-call.com/endpoint';
- const data = JSON.stringify({id: '200'}); //JSON.stringify() will convert a value to a JSON string. By converting the value to a string, we can then send the data to a server.
- xhr.responseType = 'json';
- xhr.onreadystatechange = () => {
- if (xhr.readyState === XMLHttpRequest.DONE){
- return xhr.response;
- }
- }
- xhr.open('POST', url);
- xhr.send(data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement