By David Mytton


By David Mytton

I was excited to read the AJAX: Usable Interactivity with Remote Scripting article by Cameron Adams in the hope of finding out out a lot more about AJAX, particularly how to actually use it! The article is very good, but is written as a usability guide rather than a technical howto about how to use AJAX within your own applications. Granted, I haven’t looked much, but tutorials for making use of AJAX with PHP seem to be lacking (do you know of any good ones?). So I went to Google and searched to see what I could come up with, hoping I’d find some kind of stuff Ruby has.

The first thing I came across was SAJAX which looks pretty good, although I didn’t stop to have a closer look. Next I found a PHPBuilder tutorial, which had some links in the comments, one of which was CPAINT.

I downloaded CPAINT because it looked very interesting and designed with PHP (and ASP) in mind. Reading the documentation that comes with the download, this does seem to be true. It even provides functions to generate the XML. It is certainly something I will look at again in the future if I ever decide to use AJAX. There are some people who think that AJAX is used too much!

  • Nico Edtinger

    Start reading the blog! That’s really strange. Harry has posted about working with XMLHttpReq last year – before someone called it AJAX. And now you go outside to find what you could find just in the same blog?

    The project Harry made is called JPSpan and can be found here: He even has a great wiki there.


  • The reason that I’m not a fan of AJAX is because of its lack of cross-browser compliancy. I haven’t dabbed in it myself, but I have ordered DHTML Utopia, so I should learn soon!

  • Yes Nico, Harry did indeed cover XMLHTTP last year. I thought I’d post some more about Ajax because it is now much more well known and therefore there are likely to be more libraries available. JPSpan didn’t come up in my Google search but I’m glad you have pointed it out because it looks pretty good. Thank you.

  • is not for Ruby. It doesn’t have anything to do with a server-side language. It’s a javascript library, pure and simple.

    Yes, Rails (framework, not a language) has helper functions that interact with the library, but nothing’s stopping anyone from doing the same in PHP.

  • GeirBerset

    The CakePHP-project (which is based on the Ruby On Rails concept) has made use of the prototype library (also used by the Rico-project) and it implements some ajax-functionality. Using the prototype library makes it easier to implement ajax-functionality, and makes it cross-browser compatible. The Rico-project has done this and come up with some modules which they think of as useful for us. I still suggest starting of looking at the Prototype-library before peeking at the Rico-project.

    The CakePHP-project in itself is also promising. Hopefully they will get around to creating good helper methods for the AJAX-functionality. Until then, the prototype lib and Cake is just sitting there, waiting to be used, like this guy shows.

  • I have used sajax on several projects and haven’t ran into any problems. The nice thing about sajax is the multiple languages and ease of use. I program in coldfusion at work and php on the side and it works great with both.

  • Etnu

    I’m still baffled as to why anyone would need a special api or whatnot to use these technologies. Here is what you do:

    1.) Make a request using xmlhttprequest in javascript to a server-side php script.

    2.) Make the php script process the request and return an xml file with the data.

    3.) Have the callback function (provided when you called xmlhttprequest) run through the returned data and do whatever is appropriate with it.

    The existing toolkits and apis for it are so completely unnecessary and overdone that it makes me want to cry. It’s actually slower and more difficult to use most of them than it is to just write the code yourself.

  • Etnu, I presume you feel the same way about database abstraction layers?

  • Im surprised no one mentioned JSRS… it’s by far my favourite out of the bunch so far.

    jnunemaker: im wasn’t ever able to get sajax working correctly… what’s the secret ;)

    Etnu: i have to disagree with you… I think using a complete api and toolkit simplifies the process… Why write it all over when the toolkit can do all the grunt work for you?

  • * What is AJAX?
    * Why would I want to use it?
    * What do you need to run it?
    * XMLHttpRequest sounds like a marketing buzzword – what is it and why should I care?

  • comfixit

    This site is a little odd. Ok it’s extreamly odd, but this is the most understandable AJAX tutorial out there.

  • tilika

    I’ve used Sajax on

    The benefit is that a lot of the XML gymnastics are left to Sajax and you can focus on what you want to do with Javascript and your language of choice – mine is PHP.

  • Etnu

    Etnu, I presume you feel the same way about database abstraction layers?

    Apples to Oranges.

    Databases: Enormously complex systems, each of which has unique interaction methods.

    AJAX: A tiny communications layer to facilitate the transfer of data between a DOM document and a server application.

  • I think the analogy is valid.

    I’d wager that most coders utilising AJAX would write far more lines of code to do so than they do on DB tasks. In at least two different languages!

    Also, the availability of AJAX testing tools is a long way behind what’s available for databases; meaning that the more code that you don’t have to write, the better.

  • wioota

    You use a mature toolkit because someone has experienced and generally coded around common issues such how to deal properly with latency. They also provide mappings from JS functions to PHP functions etc.

  • AJAX: A tiny communications layer to facilitate the transfer of data between a DOM document and a server application.

    the sitaution is a bit more tricky than when you use a DB abstraction layer!! firstly, not all browsers support XMLHttp, then the implementation of it varies from browser to browser(apparently IE vs Rest of them). then the issue is of cross-browser compatible parsing of data & output etc. like the Rico library gives you pre-defined methods and objects for several widgets like data-grids, drag-drop stuff etc. for which you’d write code again & again, so using a pre-made library that has already done most of the work for you & requires you make a few function calls to do the rest of the job, its a far better option.

    however, each to his own preferences!! database handling in languages like PHP & ASP etc. isn’t that hard or complex, so there’s no real use for a DB abstraction layer if someone thinks like you!! ;)

  • Paul Sullivan

    CPAINT v2.0.0 with many more features, greatly improved documentation, and security fixes was released today, if anyone is interested. We’ve also packed quite a few examples in there to get you going. Download it at Sourceforge.Net

  • boriscy

    AJAX is an exellent tool to make web pages for intranets and improve the user usability and in that case you don’t have to worry with the browser because you can specify the requirements for your system, so there is little to worry. I have used SAJAX it is a great toolkit but it didn’t work well with ADODB which I use it a lot so I found other versions that is OO and is based on the original script in the forum.

  • çiçek gönder

    çiçek gönder cicekclub e-reklamix ???

Get the latest in Front-end, once a week, for free.