Want to mix PHP with AJAX?

Want to mix PHP with AJAX?

AJAX is of course the current web development buzz-word and has been for the last few months. Really it’s some fancy Javascript that runs when actions happen (like moving out of a form field) and talks back to the server end of things.

In it’s basic form, your code then runs on the server and throws some XML (the X in AJAX) data back to the client-side to act on. But where can I use all my PHP code you ask? Well that’s where xajax comes into play.

xajax is one of many libraries/frameworks that has sprung up in the last 12 months. For PHP it’s one of the best in my limited experience and certainly one of the most straight forward to use.

What xajax does is wrap calls back to your PHP functions in JavaScript, hence taking most of that translation out of the way. You include the xajax libraries, declare your PHP functions you want to use on that page and then link them to the actions you want to make stuff happen.

In more detail,

The xajax PHP object generates JavaScript wrapper functions for the PHP functions you want to be able to call asynchronously from your application. When called, these wrapper functions use JavaScript’s XMLHttpRequest object to asynchronously communicate with the xajax object on the server which calls the corresponding PHP functions. Upon completion, an xajax XML response is returned from the PHP functions, which xajax passes back to the application. The XML response contains instructions and data that are parsed by xajax’s JavaScript message pump and used to update the content of your application.

Leave a Reply

Your email address will not be published. Required fields are marked *