XHR

Back to Hell-licensed code

Download xhr.js (666 bytes)

It is a little to add in XMLHttpRequest "library". Native XMLHttpRequest is as simple as can be, most "enhancement" is just blackboxing the obvious.

What XHR does:

Syntax

Promise XHR(string server[, object|string? get[, object|string? post[, fn? Pfn[, fn? Efn]]]])
<input type="number" id="number1" value="1" autocomplete="off"> <button id="btn1">Get number in English</button> <output id="out1">using GET method</output> <script src="src/xhr.js"></script> <script> btn1.onclick = _=> XHR('https://janturon.cz/number.php', {value: number1.value}) .then(data => out1.innerHTML = data.response); </script>
<input type="number" id="number2" value="1" autocomplete="off"> <button id="btn2">Get number in English</button> <output id="out2">using POST method</output> <script> btn2.onclick = _=> XHR('https://janturon.cz/number.php', null, {value: number2.value}) .then(data => out2.innerHTML = data.response); </script>