This is the (slightly) stripped down version of the https://github.com/aretecode/aj
-
-
Save aretecode/d558abb1397e16af1302 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param {} d .cb = callback, .m = method, .u = url, .d = data, .ct = contenttype | |
* | |
*/ | |
function aj(d) { | |
// make a XMLHttpRequest, hope it is not an old IE & FF browser | |
var request = new XMLHttpRequest(); | |
// pass in a callback | |
request.onreadystatechange = d.cb; | |
// if the method is GET, add a `?` & the data | |
request.open(d.m, d.u + (d.m == "GET" ? "?" + d.d : "") , true); | |
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | |
// use the contenttype | |
request.setRequestHeader('Content-type', d.ct); | |
// send the data | |
request.send(d.d); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function aj(e){var t=new XMLHttpRequest;t.onreadystatechange=e.cb,t.open(e.m,e.u+("GET"==e.m?"?"+e.d:""),!0),t.setRequestHeader("X-Requested-With","XMLHttpRequest"),t.setRequestHeader("Content-type",e.ct),t.send(e.d)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 aretecode | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "aj", | |
"description": "Smallest & fastest ajax library with differentiations according to the use case.", | |
"keywords": [ | |
"ajax", | |
"javascript" | |
"request", | |
"callback", | |
"http" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<title>Aj(ax)</title> | |
<div>Expected value: <b>0 then 404</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
function aj(e){var t=new XMLHttpRequest;t.onreadystatechange=e.cb,t.open(e.m,e.u+("GET"==e.m?"?"+e.d:""),!0),t.setRequestHeader("X-Requested-With","XMLHttpRequest"),t.setRequestHeader("Content-type",e.ct),t.send(e.d)} | |
var test = function() { | |
aj( | |
{ | |
u: "url.php", | |
m: "GET", | |
ct: "application/x-www-form-urlencoded", | |
cb: function(response){document.getElementById("ret").innerHTML = response.target.status }, | |
d: "test=true" | |
} | |
); | |
} | |
test(); | |
</script> |
Here's a reduced version in 139 bytes:
function aj(e,t,i){t=new XMLHttpRequest;t.onreadystatechange=e.cb;t.open(e.m,e.u,!0);for(i in e.h)t.setRequestHeader(i,e.h[i]);t.send(e.d)}
e = {
m: 'post',
u: "url.php?get=parameters",
h: { "Content-Type": "application/x-www-form-urlencoded", "X-Requested-With": "XMLHttpRequest" },
d: "data=true",
cb: function() { /* callback */ }
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alas, that's far more than 140bytes (217). Let's golf!