Get the HTML page markup (data) from the server using fetch ().
Publication on the topic: https://efim360.ru/fetch-kak-poluchit...
00:00 The task is to get the markup of the site page using fetch ()
01:40 A simple GET request in fetch () returned us the Promise
03:00 Theoretical part. FETCH and XMLHTTPREQUEST standards. Response class. Mixin Body
06:00 Promise returns a promise
07:00 Second call to then ()
07:40 Received the markup data of the requested page in the browser console
08:50 Save the data to the prepared variable
11:20 You can screw up the functionality to the page scanner
14:00 The problem of sampling. CORS policy.
Thanks for watching!
fetch () is a browser API. It lives in browsers, its logic is described in the standard - https://fetch.spec.whatwg.org/
fetch () returns a Promise object. The first result of a Promise object is a Response object.
The body of the Response object contains all the data we need. But this data needs to be read correctly.
There are only 5 options for reading:
arrayBuffer ()
blob ()
formData ()
json ()
text ()
To work with ASYNCHRONICITY, we use the then () methods, which are properties of the Promise prototype object.