Skip to content

Instantly share code, notes, and snippets.

@segdeha
Last active June 23, 2020 04:21
Show Gist options
  • Save segdeha/5601610 to your computer and use it in GitHub Desktop.
Save segdeha/5601610 to your computer and use it in GitHub Desktop.
Smallest possible Ajax implementation (120 characters)
function a(u,c){var x=new XMLHttpRequest;x.open('GET',u);x.onreadystatechange=function(){3<x.readyState&&c(x)};x.send()}
@segdeha
Copy link
Author

segdeha commented Apr 17, 2017

The c stands for “callback”, so you pass in a function to get run (and passed the XMLHttpRequest object) when the request returns.

@p-i-
Copy link

p-i- commented Jun 23, 2020

Using commas instead of semicolons means you can get away without the {}, so you could shave off a couple more characters :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment