April 2017
Intermediate to advanced
454 pages
12h 51m
English
Most of the magic happens in the submit method. In the first line, we are creating an XMLHttpRequest object, which is a native JavaScript mechanism to make AJAX requests:
const xhr = new XMLHttpRequest()
We then use the open and setRequestHeader methods to configure a new connection; we want to send a POST request, and we will send some JSON along with it:
xhr.open('post', 'http://jsonplaceholder.typicode.com/posts') xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
Since we are interacting with a RESTful interface, the POST method means that we expect our request to modify data on the server (in particular, create a new post), and that issuing the same request more than one time will get different ...
Read now
Unlock full access