Path

ez projects / ezxajax / forum / general / returning values - setting...


Returning Values - Setting XAJAX to "Synchronous" mode?

You need to be logged in to post messages in the forums. New users may register here.

Paul Wilson

Paul Wilson

Member since:
09 January 2008

Posts: 7

Wednesday 21 May 2008 4:19:06 pm

Hi,

I'm trying to use XAJAX to return values to javascript. For example:



[in PHP Code...]


$objResponse = new xajaxResponse();


$objResponse->setReturnValue('Hello World');


return $objResponse;



However for this to work, I need to enable "synchronous" mode for the xajax function being called ("synchronous" means that the browser will wait for the xajax response before executing the remaining Javascript).

I'm guessing this means:
1) adding optional parameter(s) to xajax.ini files to flag synchronous mode for a given xajax function;
2) modifying extension/ezxajax/autoloads/xajaxoperator.php to allow parameters/arguments to be assigned when functions are registered with xajax.

Has anyone done this, or perhaps there is a better way I've missed?

- Paul

(ref on synchronous xajax: http://xajaxproject.org/wiki/Xajax_0.5:_Tips_and_Tricks:_New_Features )

Moderated by: Kristof Coomans

Up

Kristof Coomans

Member since:
12 February 2004

Posts: 68

Wednesday 21 May 2008 11:19:11 pm

Hi Paul

As far as I know, it's enough to call the xajax function this way:



xajax.call( 'myFunction', { mode:'synchronous', parameters['myDiv', 'some new content'] } );




I did not find any option to register a function as synchronous by default on the PHP side in the documentation, but I must say it's a long time ago I've been looking into xajax.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Up

Kristof Coomans

Member since:
12 February 2004

Posts: 68

Wednesday 21 May 2008 11:39:43 pm

It seems only possible to set all ajax requests to be called synchronous by default:



$xajax->configure( 'defaultMode', 'synchronous' );




Apparently, the configure method replaces the setFlag method, which was introduced earlier and adopted by the ezxajax extension but deprecated now. Currently, only boolean values can be configured with the settings in the xajax.ini [Flags] group.



$flags =& $ini->group( 'Flags' );


foreach ( $flags as $flagName => $flagINIValue )


{


   $normalizedFlagValue = strtolower( trim( $flagINIValue ) );


   $flagValue = ( $normalizedFlagValue == 'enabled' || $normalizedFlagValue == 'true' );


   $xajax->setFlag( $flagName, $flagValue );


}



I suggest we modify the current behavior a bit, to change values automatically to booleans only when they are either enabled, true (=> boolean true) or disabled, false (=> boolean false). Maybe we should even rename the group to something like [Configure]?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Up

Paul Wilson

Paul Wilson

Member since:
09 January 2008

Posts: 7

Thursday 29 May 2008 9:50:08 am

Hi Kristof,

Thanks for your replies.

For the moment, I have changed the file /extension/ezxajax/autoloads/xajaxoperator.php by adding the following code (as you suggested). I added it line 68.
$xajax->configure( 'defaultMode', 'synchronous' ); 

Yes, this sets all ajax requests to "synchronous".

Looking at the Flag options in xajax.ini, my understanding is that it may be useful to have two options:
1) setting the 'defaultMode' as either 'synchronous' or 'asynchronous', and
2) overriding the default to set a particular xajax function call (eg xajax_helloworld) as being either 'synchronous' or 'asynchronous'.

I see what you mean about the changes from xajax_setFlags to $xajax->configure (ref for other readers: http://xajaxproject.org/wiki/Upgrading_from_xajax_0.2_to_xajax_0.5).

Another method might be to have different call functions according to whether synchronous/asynch is required. For example "xajax_synchronous_helloworld()" or xajax_asynchronous_helloworld()". This seems to be the way that the YUI connection manager works (http://developer.yahoo.com/yui/connection/). For example:

//With our callback object ready, it's now time to    


//make our XHR call using Connection Manager's   

//asyncRequest method:   

YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);   


(this code is from http://developer.yahoo.com/yui/examples/treeview/dynamic_tree.html)

One thing that concerns me a little is that, although there is a new xajax version in the pipeline, there does not seem to be much activity on the xajaxproject.org site at the moment (eg most recent blog post Jan 08). Perhaps it may be worth waiting to see if the project regains some momentum before developing this extension further.

Regards

- Paul
Up

You need to be logged in to post messages in the forums. New users may register here.