I wanted to see how small you could make a fully functional AJAX script that worked cross-browser and degraded gracefully, so I went through an old custom AJAX script and made it as small as I possibly could. In the resulting AJAX scripts, the post version is 410 characters and the GET version is only 359 characters long. The scripts are fully functional and accept the following parameters: URL, DATA (in string form), and ELEMENT (to update).
The scripts could be a little smaller, but it would really kill readability.
“Get” AJAX Script
function a(l,d,u){try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}if(r){r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}r.open('GET', l+'?'+d, true);r.send(d);}}
“Post” AJAX Script
function b(l,d,u){try{r = new XMLHttpRequest();} catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');} catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}if(r){r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML=r.responseText;}}r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');r.send(d);}}
Combined AJAX Script
This combined script also accepts a fourth parameter ‘p’ that should evaluate true if the data is to be sent by post.
function a(l,d,u,p){try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}if(r){r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}if(p){r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');}else{r.open('GET', l+'?'+d, true);}}}
Demo: (Sorry but you will have to go to the full page so the JavaScript is loaded.)
The best thing to come out of YouTube since the Kiwi: the Gummy bear song.
Oder, ich bin ein gummi Bär; ich bin ein gummi Bär.
All right, all right. Back to your regularly scheduled broadcasting.
I’m a post grad.
We were already declared geniuses, but now I (and through extension you) are all post grads.
On a more serious note. Link spammers are getting very sneaky. Be very careful when you paste anything into your blog even images like this one. (The original image code included spam links.) Both of these came from criticsrant.com, so be careful and always read the text included in all html code.
Linkage brought to you by: "My feeds. You’ve kept me entertained, now I’m returning the favor." Also by the letter 'A'.
Ever wondered or cared what I read in the mornings?
- [RSS] Aardvarchaeology
- [RSS] Accelerating Future
- [RSS] Adventures in Ethics and Science
- [RSS] Aetiology
- [RSS] Anthology of Ideas Yah, I subscribe to my own feed…but only so I can make sure everything comes out nice…
- [RSS] Astronomy Buff
- [RSS] Bad Language
- [RSS] behindthebuzz.com
- [RSS] Blog Maverick
- [RSS] Chris Garrett on New Media
- [RSS] Cocktail Party Physics
- [RSS] Cognitive Daily
- [RSS] Comics at GiantITP.com One of my Favorite Webcomics
- [RSS] Copyblogger
- [RSS] Cosmic Variance
- [RSS] CSS Beauty Gallery Entries
- [RSS] Deep Sea News
- [RSS] evolgen
- [RSS] FOSSwire
- [RSS] Freelance Switch
- [RSS] Functioning Form: Interface Design
- [RSS] Google Tutor
- [RSS] hicksdesign - journal
- [RSS] /home/liquidat
- [RSS] I Can Has Linux?
- [RSS] iface thoughts
- [RSS] Jatecblog - Linux, Open Source, Web Design, and more.
- [RSS] Life of a Lab Rat
- [RSS] Lorelle on WordPress
- [RSS] MAKE Magazine: Weekend Projects
- [RSS] Mapping The Web
- [RSS] Mark Evans
- [RSS] Mikko’s blog
- [RSS] Nerdaphernalia
- [RSS] NPR: This I Believe
- [RSS] Of Two Minds
- [RSS] Official Google Blog
- [RSS] outbreak
- [RSS] Performancing.com - Helping Bloggers Succeed
- [RSS] Pharyngula
- [RSS] Retrospectacle: A Neuroscience Blog
- [RSS] ruhlman.com
- [RSS] Snook.ca
- [RSS] Techdirt
- [RSS] Terminally Incoherent
- [RSS] The Long Tail
- [RSS] The Loom
- [RSS] The Montoya Herald
- [RSS] The noob
- [RSS] TorrentFreak
- [RSS] Ubuntu Tutorials : Dapper - Edgy - Feisty - Gutsy
- [RSS] Uncertain Principles
- [RSS] Unruled Notebook
- [RSS] WordPress › Support Tag: ajaxd-wordpress
- [RSS] xkcd.com
- [RSS] Zooillogix
That covers most everybody.
Looking for locksmith; will pay 550 thousand dollars.
I was going to help this poor man, but “offortunitely,” I don’t have a hammer. Maybe you can?
Dear Sir,
This is john kamara from Liberia West Africa. I am the only son of my father. My late father was the managing director of gold and diamond company in my country. And he use his position then to make away for me and my only mother.
Right now. I am in Ghana and I came dawn with a consignment worth 5.5million dollars. At the moment. The consignment is right here with me in my hotel room.Upen my arrival yesterday in Ghana.i tried to open the box but offortunitely. The key get brook on my hands.
This evening i decided to go the internet cafe to search for a God fearing somebody that can assist me to open the box and he will also invest the funds for me .I am ready to give %10 of the total funds to you before any investment.

Sobe Life water is presenting a new website http://www.thrillicious.com/ and is using dancing Lizards to do it. I’m partial to reptiles, so this is one of the best commercials I’ve ever seen. Want to see the commercial? Watch it below or go to the website and click on the Super Bowl Ad link.
Some More Pictures of this wonderful commercial:(All images are copyright their owners.)





