@megagames.me/fetchfile v1.2.2
Fetchfile.js
The simplest way to use Ajax for beginners.
About
We all love Ajax, right? But, JavaScript just messed it up. You have to use the most annoying syntax ever: XMLHttpRequest, or XHR. It is an absolute pain to write it out. But, I decided to create a library that can fit XHR into one line of JS code. It is called Fetchfile.js.
Comparison
XHR
//XMLHttpRequest
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("ajaxoutput").innerHTML = this.responseText;
}
};
xhttp.open("GET", "path/to/file.txt", true);
xhttp.send();
Fetchfile.js
Fetchfile("path/to/file.txt", false, "text", "#ajaxoutput");
They do the exact same thing, but one is by far the easiest to write.
Installation
npm
To install Fetchfile.js on npm, run the command npm i @megagames-me/Fetchfile.js
.
Important: Fetchfile.js requires jQuery 3.4.1 as a dependency.
CDN
To import Fetchfile.js into your HTML project, use this code.
<script type="text/javascript" src="//code.jquery.com/jquery-3.4.1.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/gh/megagames-me/Fetchfile.js@1.2.2/fetchfile.min.js"></script>
Note: If you want to, you can use the beta version here:
<script type="text/javascript" src="//gitcdn.link/cdn/megagames-me/Fetchfile.js/f6c5f716e3d84d9b3ef230a67322ed827509a76e/beta/fetchfile.js"></script>
This is not recommended, as it uses the latest beta version. This, however, is NOT a release! It is just the file straight from GitHub raw. This may change, so this is not recommended for production usage.
Parameters
Fetchfile(filepath, secure, outputType, whitespaceType, returnId, saveto, callback);