Topic: Easy XAjax startup class

Here's a nice, easy, class-based way to get yourself up and running with xajax.

Functions that require xajax are automatically registered, as long as the function name starts with AJAX_

* Save this as an appropriate filename (eg: ajaxtest.php)
* Download xajax into an appropriate directory within /var/www/html
* Change the XAJAXBase and XAJAXHTMLBase variables
* Modify the Output() function to your requirements
* Change the AJAX_function function as appropriate (or add more)
* Point your browser at this file.

Regards,

Leigh.

<?php
    class EasyXAjax
    {
        var $xajax;
        var $DEBUG=0;
        var $XAJAXBase="/var/www/html/path/to/xajax";
        var $XAJAXHTMLBase="/path/to/xajax";
        var $XAJAXPlugins=0;

        function __construct() {
            $AJAXAvailable=$this->InitAJAX();
            if($AJAXAvailable) {
                if($this->xajax->canProcessRequest()) {
                    $this->xajax->processRequest();
                    return;
                }
            }

            print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
            print "<html>\n";
            print "<head>\n";
            print "<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\">\n";
            if($this->xajax) {
                print $this->xajax->getJavascript();
            }
            print "</head>\n";
            print "<body>\n";

            $this->Output();

            print "</body>\n";
            print "</html>\n";
        }

        function InitAJAX()
        {
            $methods=get_class_methods(get_class($this));
            # Should we load xajax at all?
            if(preg_grep("/^AJAX_/",$methods)) {
                include_once($this->XAJAXBase . "/xajax_core/xajax.inc.php");
                $this->xajax=new xajax();
                $this->xajax->configure('javascript URI', $this->XAJAXHTMLBase);
                if($this->DEBUG >= 1) {
                    $this->xajax->configure("debug", true);
                }

                # Do we need plugins?
                if($this->XAJAXPlugins) {
                    require_once($this->XAJAXBase . "/xajax_core/xajaxPlugin.inc.php");
                    require_once($this->XAJAXBase . "/xajax_core/xajaxPluginManager.inc.php");
                }

                foreach($methods as $method) {
                    if(preg_match("/^AJAX_/",$method)) {
                        unset($xuf);
                        $xuf = new xajaxUserFunction(array($method,&$this,$method), null);
                        $this->xajax->register(XAJAX_FUNCTION,$xuf);
                    }
                }
            }
            if($this->xajax) {
                return(1);
            }
        }

        function Output()
        {
            print "<html>\n";
            print "<body>\n";

            print "<div id='ReplaceMe' onClick='xajax_AJAX_function(\"boo\");'>CLICK ME</div>\n";

            print "</body>\n";
            print "</html>\n";
        }

        function AJAX_function($text)
        {
            $objResponse=new xajaxResponse();
            $now=time();
            $objResponse->assign("ReplaceMe","innerHTML","New Content: $now ($text)");
            return($objResponse);
        }
    }

$object=new EasyXAjax;
?>

2 (edited by Robert Fulton 2012-07-01 4:42:25 PM)

Re: Easy XAjax startup class

We can Download xajax into an appropriate directory within /var/www/html

Environmental management system

Re: Easy XAjax startup class

The coolest new change in this version is $().SPXmlTo.Json. This is due to the launcher had been getting quite a few request over the years to output JSON rather than only XML. He was resistant up to some degree due to not being completely clear of the number of people using it. But now when we along with him can see remarkable improvement in the use of jQuery which is more common part used in SharePoint development toolswhat is htmlthen the final decision would definitely to add it. In SPXmlToJsonwhat is it doing is taking the XML output and then converting into JSON. It will definitely add on to some overheads thus outsource sharepoint development companies are advised to use it wisely. The initial implementation is focused on GetListItems but is also going to work with flat XML. Some developers require further enhancements to the function.