AboutBlogContact
Web DevelopmentNovember 20, 2004 2 min read 131Updated: June 22, 2026

xajax: Building Interactive PHP Apps Without the JavaScript Headache (2004)

AunimedaAunimeda
📋 Table of Contents

xajax: Building Interactive PHP Apps Without the JavaScript Headache

It's late 2004, and the "Web 2.0" revolution is picking up speed. We all want our apps to feel like Gmail or Google Maps, but let's be honest: writing XMLHttpRequest code that works in both Internet Explorer 6 and Mozilla Firefox is a nightmare. This is where xajax comes in. It’s a PHP library that lets you call PHP functions from JavaScript and update the page content directly from PHP.

How it Works

xajax generates the necessary JavaScript for you. When you call an xajax function, it sends a request to the server, executes your PHP function, and then returns a "Response" object containing a list of commands (like "assign this value to this div") that the xajax JavaScript engine executes on the client.

Setting up a Simple Update

First, we define our PHP function and register it with the xajax object.

require("xajax.inc.php");

$xajax = new xajax();

function updateMessage($text) {
    $objResponse = new xajaxResponse();
    // Directly manipulate the DOM from PHP!
    $objResponse->addAssign("content_div", "innerHTML", "You typed: " . $text);
    return $objResponse;
}

$xajax->registerFunction("updateMessage");
$xajax->processRequests();

The HTML Side

In your HTML, you just need to include the generated JavaScript and call the function using the xajax_ prefix.

<html>
<head>
    <?php $xajax->printJavascript(); ?>
</head>
<body>
    <input type="text" id="myInput" onkeyup="xajax_updateMessage(this.value);">
    <div id="content_div">Type something above...</div>
</body>
</html>

No More eval()

The beauty of xajax is that it handles the serialization and the DOM updates for you. You don't have to worry about parsing JSON (which isn't even popular yet) or XML manually. You just think in terms of PHP logic. While some purists argue that we should keep our "behavior" (JS) separate from our "logic" (PHP), xajax is a godsend for PHP developers who want to stay productive in a rapidly changing web landscape.


Aunimeda develops websites and web applications for businesses - corporate sites, e-commerce, portals, and custom platforms.

Contact us to discuss your web project. See also: Web Development, E-commerce Development

Read Also

SolidJS: Fine-Grained Reactivity and the Death of the Virtual DOM (2021)aunimeda
Web Development

SolidJS: Fine-Grained Reactivity and the Death of the Virtual DOM (2021)

React is great, but why are we re-running our whole component tree? SolidJS proves that fine-grained reactivity is the faster path.

Svelte 3: The Framework that Disappears (2019)aunimeda
Web Development

Svelte 3: The Framework that Disappears (2019)

Svelte 3 is here, and it's doing away with the Virtual DOM entirely. Reactivity is now a language feature, not a library feature.

The TypeScript Tipping Point: Why We Stopped Shipping Raw JavaScript in 2018aunimeda
Web Development

The TypeScript Tipping Point: Why We Stopped Shipping Raw JavaScript in 2018

The days of 'undefined is not a function' are numbered. In 2018, we have officially moved all new agency projects to TypeScript. Here is why static typing is the best investment for long-term project health.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Web Development

Get Consultation All articles