xajax not working

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
irish
Forum Members
Forum Members
Posts: 101
Joined: Tue Jun 03, 2008 2:31 pm

xajax not working

Post by irish »

Has anyone figured out how to use xajax for front-end development? I can get xajax to work in the admin area but when I tried to use it on the action.default.php page, it does work correctly. The ajax call will bring back the entire page plus the xml request.

I have added the methods per this topic: http://forum.cmsmadesimple.org/index.ph ... 909.0.html but it didn't help.

Here is the code I have so far:

Code: Select all

require_once($_SERVER['DOCUMENT_ROOT'] .'/lib/xajax/xajax.inc.php');
$xajax = new xajax();
$xajax->registerFunction('myFunction');

$xajax->processRequests();
$this->smarty->assign('js',$xajax->getJavascript($config['root_url'] . '/lib/xajax')."\n");

function myFunction($arg)
{
    // do some stuff based on $arg like query data from a database and
    // put it into a variable like $newContent
    $newContent = "Value of $arg: ".$arg;
    
    // Instantiate the xajaxResponse object
    $objResponse = new xajaxResponse();
    
    // add a command to the response to assign the innerHTML attribute of
    // the element with id="SomeElementId" to whatever the new content is
    $objResponse->addAssign("IntroRt", "innerHTML", $newContent);
    
    //return the  xajaxResponse object
    return $objResponse->getXML();
}
irish
Forum Members
Forum Members
Posts: 101
Joined: Tue Jun 03, 2008 2:31 pm

Re: xajax not working

Post by irish »

Never mind, I just got it working. I can't believe I spent days trying to get this to work and as a last resort posted this topic here. After posting the topic, I went back to it and tried a few more things eventually found the answer:

Code: Select all

require_once($_SERVER['DOCUMENT_ROOT'] .'/lib/xajax/xajax.inc.php');
$xajax = new xajax();
//$xajax->registerFunction('ajaxGetIntro');
$xajax->registerFunction('myFunction');

$xajax->processRequests();
$this->smarty->assign('js',$xajax->getJavascript($config['root_url'] . '/lib/xajax')."\n");

function myFunction($arg)
{
    
$handlers = ob_list_handlers(); 
for ($cnt = 0; $cnt < sizeof($handlers); $cnt++) { ob_end_clean(); }

	// do some stuff based on $arg like query data from a database and
    // put it into a variable like $newContent
    $newContent = "Value of $arg: ".$arg;
    
    // Instantiate the xajaxResponse object
    $objResponse = new xajaxResponse();
    
    // add a command to the response to assign the innerHTML attribute of
    // the element with id="SomeElementId" to whatever the new content is
    //$objResponse->assign("IntroRt","innerHTML", $newContent);
    $objResponse->addAssign("IntroRt", "innerHTML", $newContent);
    
    //print_r($objResponse->getXML());
    
    //return the  xajaxResponse object
    return $objResponse->getXML();
}

Notice the "ob_end_clean" in the function.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: xajax not working

Post by calguy1000 »

add showtemplate=false to the URL.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
irish
Forum Members
Forum Members
Posts: 101
Joined: Tue Jun 03, 2008 2:31 pm

Re: xajax not working

Post by irish »

calguy? what do you mean?

It's javascript that calls the Ajax using an onclick event.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: xajax not working

Post by calguy1000 »

Code: Select all

        /*
                Constructor: xajax

                Constructs a xajax instance and initializes the plugin system.

                Parameters:

                sRequestURI - (optional):  The <xajax->sRequestURI> to be used
                        for calls back to the server.  If empty, xajax fills in the current
                        URI that initiated this request.
        */
so grab the current request URI, add &showtemplate=false to the end of it... pass it to the xajax constructor.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
irish
Forum Members
Forum Members
Posts: 101
Joined: Tue Jun 03, 2008 2:31 pm

Re: xajax not working

Post by irish »

hhhmmmm, Interesting. However, it brings back all the content of the page and not just the xml response.
Post Reply

Return to “Developers Discussion”