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. »

Oh, as an Aside: AJAXed WordPress (From the 10th of November)

AJAXed Wordpress (AWP) harnesses the power of both AJAX and Wordpress to improve the user experience, the administration capabilities and the design potential of any Wordpress based blog. It works on all WordPress versions from 2.1 – 2.6.

NEW VERSION AND NEW WEBSITE!

AJAXed WordPress has its own website at ajaxedwp.com. All updates and support are now given there.

Trapping WordPress errors with output buffering.

If you have tried to use AJAX with WordPress, most likely you have stumbled upon the wp_die() function which completely kills the response you expect to get. However, we can trap the wp_die() by using PHP’s output buffering and the ob_start callback function to process the output of wp_die() even though a die() is called. This is a very special case, and will only work when you are able to ensure output buffering can be called before the die is called.

The easiest way to get a non-fatal wp_die() error (an error that shouldn’t cause the entire application to stop) is when submitting comments: non-fatal errors occur whenever someone posts too quickly or submits a duplicate comment, so this can be a problem when creating an AJAX app to submit comments (I ran into this problem with INAP.)

Since AJAX makes the entire submit process very quick, so it is easy to trigger the “Posting too quickly” error if the user make short comments, and when this happens an entire page –complete with CSS and headers– is returned as the AJAX response.

Continue reading. »

INAP 3.0 Progress

Aside from a brief flirtation with a couple payed projects, I’ve been heavily focusing on rewriting the code for INAP 3.0, and it has almost reached the point of a private beta (which means I start running it on this site.) I have selected the new name for INAP 3.0, but I’m not going to reveal it just yet. Here is a small preview of what you can expect from INAP 3.0:

INAP 3.0 is now truly modular with a main Javascript/PHP core that other features hook into to function. This core is easily extensible and the new structure of a main project with many smaller projects will make bugfixes and upgrades less painful, and will allow the user to upgrade the plugin section by section as most changes in the modules won’t effect the core.

For the users:

  1. INAP 3.0 will make upgrades far less painful.

Continue reading. »

Extra, Extra Read all about it, INAP and feed problems on the 28th of July

If you use INAP and have noticed oddness with your full-text feeds lately, it may have been caused by INAP. Users that had the “custom options” selected would have their feeds trimmed as if it were a post. INAP 2.4.3 fixes this.

In other news, INAP is in the process of a major overhaul including a complete rewrite of most of its antiquated structure. When this process is complete it will be rebranded to demonstrate the totality of its features (it won’t be called INAP anymore because the name is too restrictive), but will be released as version 3.0

Extra, Extra Read all about it, INAP listed on Mashable on the 22nd of July

Inline Ajax Page was listed on Mashable as one of “30 good [AJAX wordpress plugins].” While I’m thankful for the publicity (it seems half the internet is scraping Mashable’s feed which resulted in a huge Technorati boost), as always, it was described as “Allow[ing] readers to see a snippet of a post, click a button and the remainder will appear without going to another page.”

I almost cried. That description fits only the 1.0 version of INAP that was released over a year ago–now it does so much more than that that it is almost like saying Google is just a search engine. Oh well, the traffic generated was good quality.

In other news, version 2.4.25 was released a couple days ago to fix a bug that occurs when submitting a comment using the jQuery library under IE6.

Continue reading. »