Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en" id="html">
- <head>
- <meta charset="UTF-8">
- <title>XHR</title>
- <style>
- html,
- body {
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .container {
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-content: center;
- align-items: center;
- margin-top: 30px;
- position: relative;
- }
- .mainDiv {
- display: flex;
- flex-direction: row;
- }
- table, tr, td {
- border: 1px solid black;
- border-collapse: collapse;
- padding: 5px;
- }
- table {
- width: 70%;
- margin: 10px;
- }
- </style>
- </head>
- <body>
- <div id="container" class="container">
- <input type="number" id="userId">
- </div>
- <script>
- 'use strict'
- //function getUser()
- let url = 'https://jsonplaceholder.typicode.com/users';
- let method = 'POST';
- let newUser = { id: 2607, name: 'avr39-ripe', company: 'itstep' };
- let xhr = new XMLHttpRequest();
- xhr.open(method, url);
- xhr.setRequestHeader('Content-type','application/json; charset=utf-8')
- xhr.addEventListener('load', function () {
- if (this.status >= 400) {
- console.log(`HTTP ERROR CODE: ${this.status}!`);
- }
- else {
- console.log(this.responseText);
- }
- });
- xhr.send(JSON.stringify(newUser));
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement