I’ve been too lazy to transfer my holiday photos from my camera since I cam back (because then everyone will crowd around my computer and ooh and ahh at every.single.picture - even the ones of a thumb obscuring the lens) instead though, I have bitten the bullet and finally got around to creating some Mysql tables for the remote script that does the fetching of the last blog post for commentluv plugin users.
What does this mean? ..
it means that I can create a site for people to register their blog url and with that :
Other things I will be able to do with the upcoming commentluv site now I’m using a database to store data..
If there’s more things you’d like to be able to do with commentluv on your blog or features you’d like to see for a commentluv site please leave a comment here and let me know… (btw.. I am using a new version of commentluv on this site that uses the new remote script and database, if you get any issues with comments going funny please let me know on the contact page)
..oh, one more thing… ajax commentluv is a little more improved, it can now work with almost any blog that allows you to edit the header of your theme! .. it’s still a little way off from a release but it seems to be working well … stay tuned!
Popularity: 2% [?]
I spent a large part of last weekend coding some changes to CommentLuv, well, changing the way it can be called and how it displays posts and such. Here’s a little preview of what sort of thing it can do on a dummy form, let me know if it can’t pick up your last post or if you experience any issues with it…
This is running as just javascript and jquery without using any of the wordpress core functions and it should work on standard forms on sites that don’t have PHP enabled. I just need to tidy up the code and package it in an easy to install way and it’ll open up CommentLuv to many more platforms…yey!
I’m not 100% sure yet but this could mean a blogspot commentluv plugin, I’m trying some experiments now and so far the results are promising…
Popularity: 6% [?]

Hurrah! this tutorial will actually download some data (yey!) We will use everything we have learned so far and add just a little bit that will allow us to download data from the server and put it somewhere on the page without a refresh. (I know, you must have goosebumps!)
We need this command to initiate the object send. We created an object, created a place for the data to go, we created a routine to wait patiently for the object to be ready and sent the object to the data source using the above command. The patient routine for the waiting will take the response to the data source and put it in the div we created in the HTML of the page.
We can replace the bit from the last bit of complete code (on part 4) with this command and instead of it saying it's ready to download, it will actually do the fetching for the obj.innerHTML=XMLHttpRequestObject.responseText; which is called when the readyState and Status are ok.
I'll try and make this code easier to understand with a picture using pretty colours! ![]()
![]()
The blue bit gets called when the user clicks the button, if the object was successfully created then create a routine that 'listens' to the objects readyState and status. Then the XMLHttpRequestObject.send(null); command does the action and when that goes ahead and activates XMLHttpRequestObject.open("GET", dataSource); which goes off and gets the data pointed to by dataSource which of course changes the objects status and readyState. When it is at what we want, we inject the responseText to the div pointed to by divID.
Simple! :-/
You can see it in action here
Exciting huh? LOL . It'll display anything that is in the oranges.txt file, not much use yet but at least we know we can fetch data!
What if, instead of displaying the contents of a text file, we used a php script to 'echo' out something?.. replace oranges.txt with this code..
(don't forget to enclose any php script with <?php and ?> or it wont work - I cant put them in here otherwise it will run the script instead of showing the code. Also, change the onclick event in the html to call oranges.php (if you saved the php with that name) instead of oranges.txt
You can see that in action here
There may be a pause between you clicking and the message being displayed. We can let the user know that something is happening by adding another if condition to look for a readyState of 1 (loading) and displaying the message "off to get oranges..." like this..
we just chuck that into the anonymous function that is called when the readyState changes...
See that in action here
You can download all the files used in this tutorial here.
Now we're getting somewhere! But, what if we want to send data to the php file so it can do something more than print a hardcoded message?
Actually, it's quite easy! come back next week to see the final part where we'll send something to the php file and have it send back something it made with what we sent. (it could be a username or contents of a text field - think form validation!)
You can subscribe to my feed with the button at the top right of this blog or add your email to the box on the sidebar of the main page to subscribe by email. I hope you can come back and learn a bit more, enough at least to make your own php script and AJAX page....
Popularity: 10% [?]

In this part of the tutorial series we will get ready to rumble! download data using the object we created in the last part...
What the hell is that? lol, it's not move states when you're ready.. it's what we use on the object we created to see what state it is in, the different states are:
We can check for an objects state to see where it's at to decide if we can output the result or not, we can combine this with a test for the HTTP status of a download to see if it was successful, we can check for a value of 200 which means everything went ok. (a value of 404 would mean file not found just like normal HTTP status codes).
To use the readystate property, just bang it on the end of the object name and put that in an 'if' statement. Ie...
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
{do something}
(the && means AND, so we check the readystate AND the status, if they are BOTH correct then execute the code in the curly brackets)
To put that in the code of the last tutorial, replace the bit that outputs the message about the oranges box being collected with an anonymous function that is attached to the objects readystate. It's not named an anonymous function because it has a secret identity, it is just a nice way of running a function with no name when a certain thing happens like the objects' readystate being changed.
For example, if we put
XMLHttpReqestObject.onreadystatechange = function()
{
do something
}
We have attached the onreadystatechange to the object we created, as soon as that objects readystate has altered, the anonymous function takes action and executes the commands contained in the curly brackets ({do something }).
That's exactly where we put the test to see what the HTTP status and readystate number is. Ie.
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
{
data downloaded, do something with it...
}
}
You may have noticed little graphics that are synonymous with web 2.0 and AJAX (
). You can add one of those to let the user see something is happening. In the code above, you can check for a readyState of 1 (loading) and add some text like this:
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 1)
{
obj.innerHtml="Loading...";
}
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
{
data downloaded, do something with it...
}
}
The FiddyP amazing analogy:
Last time we had created a box for the oranges that we want from the AJAX shop
XMLHttpRequestObject = new XMLHttpRequest();
then we opened it and sent it to the AJAX shop with a label of what we want.
XMLHttpRequestObject.open("GET", dataSource);
And we wait for the signal that the box we sent was filled ok and ready to go
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
Your whole code will now look like this...
OK, so you have your box at the AJAX shop full of oranges.txt, next tutorial we'll do something with the oranges...
If you've been following the other tutorials then the code above shouldn't be so hard to understand (shyeah right!), it's just a bit more added to what we've already covered. You can copy the code from above and try it out yourself or you can click here to see it in action (hold on to your hat :-P)
We're still in the AJAX starting blocks waiting for the bang to start us on the AJAX runway but don't despair, next tutorial we will actually download data from a server and display it on the page without a reload which is what AJAX is all about. Once we can actually display the data, we can start doing things with it and then we can start to make pretty little scripts that do amazing things like count the amount of times a pink box has been clicked. hehehe, we'll do more than that I promise!
Popularity: 9% [?]

In this part of the tutorial series we will open the object that you created in the last tutorial. So far, we have created an object to handle the data and made sure it is created in whatever browser you are using. Now, if we want to work with the created object, we need to open it...
Opening the object prepares it for use to fetch the data from a server, the act of opening the object doesn't actually fetch any data yet.
The FiddyP amazing analogy :- Imagine you created a page to collect a box of oranges from the local AJAX fruit shop. In the last tutorial, you created the box (object), now you need to open it so the AJAX oranges can fit inside...
The open comand: [square brackets] = optional arguments.
open("method", "url" [, asyncFlag[, "username"[, "password"]]])
Explanation:
Make sense? lol, maybe not. Here's how it looks in use:
XMLHttpRequestObject.open("GET","oranges.txt");
We just add the open bit of code on to the end of the name of the object we created. Here's an example page where we create a form in HTML and add a button for the user to click to open a remote file on the server with AJAX. Because AJAX uses CSS to change elements of the page, we need to create a <div> on the page to show the data we retrieve from the remote file. We'll also have to create a function to take action when the button is clicked (we can't do it the normal way with the <form> action because that would cause the page to reload).
Here's the form and div html:
You can see that the button has an 'onclick' event. That's the javascript bit that calls the function when the button is clicked. The <div> has an id so the function will know where to put the collected data.
The javascript function is held in the <head> part of the document;
The function is called with the name of the data file we want (dataSource) and where to put the output (divID)
The first line checks if the XMLHttpRequestObject was created (we did that last time so you know it should get to this point)
If it finds that the object was created, it moves on to set the variable obj to the <div> we created by using getElementByID
Next, we use the open command on the object we created earlier, set the option to GET and point it to the external data file we specified when calling the function.
Once that is done, we can output a message to the <div> we assigned to the variable obj by using .innerHTML=
We'll just put this function in place of the "hello world" message that we put in the last tutorial..
The whole code looks like this...
You can copy the contents of the HTML shown above and save it as a HTML file, you can also create a file called oranges.txt and put it in the same directory as the HTML file. (it doesn't matter what is in the text file as we wont be doing anything with it other than to open it). Open the HTML file in your browser and try it yourself or click here to see it in action if you can't wait.
That's it for this week, we're still not doing anything major yet but, be happy! we have so far, created an object and opened it. YEY! come back for part 4 where we will prepare to download information from the file we opened. (oh, I bet you can't wait!!)
beep beep w00t!
Popularity: 6% [?]

In this part, we will start you off with some very simple code just to show you how things get started. At the end of this tutorial you will have made your own 'hello world' AJAX script... (not a big deal I know, but you have to start somewhere!). I'll keep these tutorials bitesize and introduce a new command or concept on each tutorial to add to what has already been covered. Today, we start at the beginning with something that will be in all future scripts...
The what? ![]()
The XMLHttpRequest object is at the heart of AJAX. It allows you to send and receive data with javascript without refreshing the page and works on all browsers (except, you guessed it! Internet Explorer). All you have to do is find out if the browser supports it with an 'if' statement in the javascript contained in the <head> part of the html page and then create a XMLHttpRequest object using the 'new' command;
That would create a XMLHttpRequest object and store it in XMLHttpRequestObject.
But, what about Internet Explorer?.. We can't use XMLHttpRequest so we have to use an ActiveXObject. For us to do anything with an XMLHttpRequest and make sure it works on both IE and Firefox, we can add this to the javascript so we now have..
OK, that should cover us for making a XMLHttpRequest object, we can't do anything in this tutorial series without it so to be sure, lets just create the whole html document and test to see if it can make an object by adding another 'if' statement to output some text to the screen if the object creation was successful using the javascript command 'document.write()'.
You can click on the title of the code snippet above and see the plain text version, just copy this to your own file and save it as an HTML document or right click here and save it and test it. If it's working, it will display the message "hello world! I created an object!" in big letters.
YEY! we created a 'hello world' AJAX program!, I know it's not much use yet but this is the foundation for all future tutorials so even thought it's not that 'sexy' , it IS important to make sure we can create the object that will handle the data being sent to and received from a remote file.
We can get into the sexy ins and outs of using this on the next tutorial. Please come back again to see how we can use this to open a remote file and display it's contents on a HTML page without a reload...(ooh, I can't wait....)
![]()
Popularity: 6% [?]

It seems more and more people want to use this type of programming method to bling their blog up to 2.0 level including me!, so come along as I traverse the wonders of AJAX. I am learning this as I go so it's not really fair to call it a tutorial series but you get the idea!
First off, we need to know what AJAX is...
The first thing to know about AJAX is that in fact, it isn't actually a programming language. It's just a way of using other languages together to create an 'application' style of interface for a web page.
The word 'AJAX' comes from a contraction of 'Asynchronous', 'Javascript', 'And', 'XML', it's purpose is to allow a web page to send and receive small bits of data 'asynchronously' while the user is still on the page and change the contents of parts of the page with the data received.
It could be something simple like automatically updating a shipping charge after a customer enters their postal code in a form or it could be something more familiar like the Google auto-guess/complete that happens when you start typing in a search term.

As soon as you start typing something in the search box, the javascript on the page detects each key press and sends it to the server which then sends back any terms that have the same letters starting the term, as you continue to type it shows a narrowing set of options and how many results they each have. You can try it out yourself at http://labs.google.com/suggest
Here are some other examples of sites using AJAX.
The important thing to remember is that AJAX is the term used when the page needs to send and/or receive data to the server asynchronously, whereas a sliding DIV or a dynamic menu is just Javascript or DHTML.
A traditional web application(using a shopping cart form example)

.. a user enters their shipping details and clicks submit, the page sends the form details and reloads again showing the shipping charge.
AJAX web application

.. a user enters their postal code and the server automatically calculates the shipping charge and returns it to the original page, all without the user having to wait for another page load. Much more efficient!
It's the work of the devil! that's how! ![]()
Seriously though, javascript, css and html are used on the browser side and a scripting language is used on the server. The scripting language can be PHP, perl, asp or any kind of get-process-return language that runs on a server.
Really, javascript is the boss for all the actions as it is responsible for orchestrating everything on the client side. ie:
The javascript detects the click, text entry or other action which initiates a call to the script on the server which responds with the data requested, the javascript receives the data and by using css and html it is able to update the page, all without the user having to wait for a page load as with traditional web pages.
Take a look at this diagram:

Probably the best data type used is XML, simply because it is a standard capable of representing complex data that would otherwise be difficult to represent. But, that doesn't mean that XML is the only type of data that can be used. You could use plain text if there was only a small amount of simple data to be sent like a name or value.
You could also use something called JSON (JavaScript Object Notation) but that's for a later tutorial (and for geekier types!)
It's important to remember that AJAX is entirely dependent on a server program accepting requests and responding to them in some way. You can't just make a web page with some Javascript on it and have an AJAX application, you need the javascript to send and receive information and do something with it.
You don't have to use the same server as the web page to do the processing, you could just as easily use a script on a remote server.
Places like Google, Flickr and others allow people to use an API (Application Programming Interface) to request information from one of their scripts on their server. Flickr for example could send back information listing a users photo locations so the AJAX page could display them.
Simply, whatever the server or javascript does, it all comes down to ; request send, request received, data processed, data sent back, data used.
On the next part of this series, we will get into the guts of an AJAX application and show you just how it works and how you can change it yourself. For now, here is an example of what you should be able to do after a couple more tutorials..
It detects a click on the pink area and sends a request to a PHP script that reads a text file containing a number, adds one to it, saves it and sends back the number to be displayed on the page. Try it yourself, it may take a couple of seconds to show the number (this is just an example, later we will add a nice AJAX'y type of wait animation). I wonder how high this number will/can go?
Come back next week for the second part of the series where we will get into the innards of AJAX and show you just whats needed to make the traditional 'hello world' program....
Popularity: 7% [?]