by prettyscripts on 2008-02-19 15:49:20
javascript • ajax • xajax
in v0.2.4, the command to display confirmation message is addConfirmCommands. in V0.5 it’s confirmCommands.
PHP:
$obj->ConfirmCommands(commands, message); |
where commands is the number of response commands to skip if cancel is clicked from the confirmation dialog.
if not to continue to execute the rest of the function:
PHP:
function some_function() { | |
$obj = new xajaxResponse(); | |
// some codes | |
$continue = 0; | |
$obj->confirmCommands(1, "Do you wish to continue"); | |
$continue = 1; // will not be skipped! see explanation below. | |
if ($continue == 0) | |
return $obj; | |
// the rest of the codes | |
return $obj; | |
} |
this does not work. the confirm is done at the client side. the server sends the command in one go and doesn’t wait for the client’s response. (according to posts from xajax forums)
the best way to do it is to break up the function to smaller functions and call that function. ie move the codes you want to continue to another xajax function.
PHP:
function some_function() { | |
$obj = new xajaxResponse(); | |
// some codes | |
$obj->confirmCommands(1, "Do you wish to continue"); | |
$obj->call("xajax_continue_function"); // this will be skipped | |
return $obj; | |
} | |
function continue_function() { | |
$obj = new xajaxResponse(); | |
// rest of code here | |
return $obj; | |
} |
an alternative way is to write a javascript to call the xajax function.
PHP:
<script type="text/javascript"> | |
function js_confirm() | |
{ | |
var yes = confirm('Do you wish to continue'); | |
if (yes) | |
xajax_continue_function(); | |
else | |
xajax_cancel_function(); | |
} | |
</script> |
Tags: confirm, javascript, xajax