Oh, as an Aside: Short Ajax Script (From the 13th of May)

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

  1. function a(l,d,u){
  2. try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
  3. if(r){
  4. r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
  5. r.open('GET', l+'?'+d, true);r.send(d);
  6. }
  7. }

“Post” AJAX Script

  1. function b(l,d,u){
  2. try{r = new XMLHttpRequest();} catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');} catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
  3. if(r){
  4. r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML=r.responseText;}}
  5. r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');r.send(d);
  6. }
  7. }

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.

  1. function a(l,d,u,p){
  2. try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
  3. if(r){
  4. r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
  5. if(p){r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');}else{r.open('GET', l+'?'+d, true);}
  6. }
  7. }

Demo: (Sorry but you will have to go to the full page so the JavaScript is loaded.)

Continue reading. »

Wordpress Code Escape

Here is another small modified plugin that auto-escapes your code, nicely displays line numbers and uses valid XHTML. This plugin is based off of SemCodeFix, and adds many of the features I wanted in my code plugin.

Download:
Wordpress Code Escape

Directions:
Download the file and save it as a .php file.
Upload to your plugins directory.
Activate it.
You may optionally choose to add the following style information to your theme’s style.css.

  1. .code_child {
  2. font-family:"Courier New", Courier, monospace;
  3. white-space:pre;
  4. width:90%;
  5. background-color: #F4F4F4 !important;
  6. overflow:auto;
  7. border:1px inset;
  8. margin:10px;
  9. }
  10. ol.code_child li{
  11. margin:0;
  12. padding:0 !important;
  13. line-height:100% !important;
  14. margin-bottom: -8px;
  15. margin-bottom: expression(5 +"px");
  16. margin-left: expression(35 + "px");
  17. }
  18. Use the following to copy and paste the code.