HTTP: Difference between revisions

Content added Content deleted
(Initial FutureBasic task solution added)
imported>Gabrielsroka
Line 1,411: Line 1,411:


===Browser===
===Browser===
Using fetch API and async/await:
<syntaxhighlight lang="javascript">
const resposne = await fetch('http://rosettacode.org');
const text = await response.text();
console.log(text);
</syntaxhighlight>

Using fetch API:
<syntaxhighlight lang="javascript">
fetch('http://rosettacode.org').then(function (response) {
return response.text();
}).then(function (text) {
console.log(text);
});
</syntaxhighlight>

<syntaxhighlight lang="javascript">var req = new XMLHttpRequest();
<syntaxhighlight lang="javascript">var req = new XMLHttpRequest();
req.onload = function() {
req.onload = function() {
Line 1,418: Line 1,434:
req.open('get', 'http://rosettacode.org', true);
req.open('get', 'http://rosettacode.org', true);
req.send()</syntaxhighlight>
req.send()</syntaxhighlight>

Using fetch API:
<syntaxhighlight lang="javascript">
fetch('http://rosettacode.org').then(function(response) {
return response.text();
}).then(function(myText) {
console.log(myText);
});
</syntaxhighlight>


As a repeatable function:
As a repeatable function: