Ajax & XUL with xajax

One interesting subject that has come up in the the xajax project forum is using our xajax library to implement PHP driven Ajax for XUL applications written to run in Mozilla based browsers like Firefox. In case you don’t know about it already, XUL is Mozilla’s XML-based User interface Language. Developers use XUL to create extensions for Firefox, among other things.

Using xajax with xul is only in the beginning stages of exploration, but I look forward to what comes out of it. While it does not work with today’s xajax beta test, I’ve made a slight modification to the development version of xajax in CVS that makes it so that it will work with XUL, and I’ve added a couple of very simple examples to the repository as well. These changes will be included in the official release of xajax 0.2 after the beta test in complete.

Here is an example for the curious. We have two files, a .php server file that processes requests from the xul application, and a .xul application xml file.

xulServer.php:

<?php
// xulServer.php demonstrates a XUL application with xajax
// XUL will only work in Mozilla based browsers like Firefox
// using xajax version 0.2
// http://xajaxproject.org
require_once("xajax.inc.php");
function test() 
{
        $objResponse = new xajaxResponse();
        $objResponse->addAlert("Hello World!");
        $objResponse->addAssign('testButton','label','Success!');
        return $objResponse->getXML();
}
$xajax = new xajax();
$xajax->registerFunction("test");
$xajax->processRequests();
?>

If you want to create a standalone XUL app that is not generated by PHP you have to hardcode the javascript variables and links in your xul code instead of using the printJavascript() function and you have to use the xajax.call() function to call your xajax functions instead of the “xajax_” functions that are normally generated by the PHP xajax library.

xulClient.xul:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<head>
        <link rel="stylesheet" type="text/css"
         href="/css/default.css"/>
        <script type="application/x-javascript">
                var xajaxRequestUri="xulServer.php";
                var xajaxDebug=false;
                var xajaxStatusMessages=false;
                var xajaxDefinedGet=0;
                var xajaxDefinedPost=1;
        </script>
        <script type="application/x-javascript"
        src="https://www.sixteensmallstones.org/xajax_js/xajax.js">
        </script>
</head>
<xul:button id="testButton" oncommand="xajax.call('test',[]);"
 label="Test"/>
</html>

I’ll be interested in seeing where our xajax users will go with this.

Category: technology
Tagged: , , , ,
Bookmark: link

One Response to Ajax & XUL with xajax

Leave a Reply

Be sure you are familiar with the Comment Policy before commenting.

Anyone who wishes to comment here must register for a sixteensmallstones.org login or connect using their Facebook account. Registration is simple and fast.

Once you have activated your account, you must log in to post comments. The first time you comment will still be moderated, but once I have approved your first comment you should be able to continue to add additional comments on any article without further impediment as long as you are logged in.