javascript: calling xajax functions with boolean parameter

by prettyscripts on 2009-06-24 10:28:46 • Leave a comment »

miscjavascriptxajax

when passing a boolean value from javascript to a xajax function, the value is converted to string in the xajax function.

you need to compare the string value of the boolean value (from javascript) in xajax function.

eg, the following code in xajax function will not work:

PHP:

function my_xajax_function($flag) {
  $obj = new xajaxResponse();
  $obj->assign('some_id_name''className'$flag'true_class' 'false_class');
  return $obj;
}

in the above code, the ‘false_class’ will always be assigned.

replace line 3 from above with the following:

$obj->assign(’some_id_name’, ‘className’, ($flag == “true") ? ‘true_class’ : ‘false_class’);

Tags: boolean, javascript, xajax

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
note: all comments are moderated. do not spam and do not advertise. only comments relevant to the post will be published.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)