Topic: display confirmation box and then reload page

I need to display an alert box asking to confirm a delete operation, if the user confirms, then remove the record and reload the page. How can I do this from an xajax function? I have used js alert, but just to display a basic message.

Re: display confirmation box and then reload page

Use the confirmCommands function of the response object:

function confirmCommands($iCmdNumber, $sMessage)
Parameters:
iCmdNumber (integer) The number of commands to skip upon cancel.
sMessage (string) The message to display to the user.

The command to execute is the first AFTER the confirmCommands.

1. $resp->confirmCommands(1,'Delete the Record?')

2. $resp->script('xajax_myDeleteFunction()');

It displays a confirm box. If the user clicks cancel, nothing happens. If the user clicks OK the xajax function is called.

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: display confirmation box and then reload page

Done! But how do I reload the page after that?

Re: display confirmation box and then reload page

Check this out:

<?php
/*
  10/30/2013
  
  reloadtest.php
  Using confirmCommands to reload the page to itself.
*/
require_once("xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');

function confirmTest()
{
   $resp = new xajaxResponse();
   $resp->confirmCommands(1,'Confirm Test');
   $resp->script("xajax_reloadPage()"); 
   return $resp;
}

function reloadPage()
{
  $resp = new xajaxResponse();
  $resp->redirect("reloadtest.php");
  return $resp;
}

$xajax->register(XAJAX_FUNCTION, "confirmTest");
$xajax->register(XAJAX_FUNCTION, "reloadPage");
$xajax->processRequest();
?>
<!DOCTYPE html>
<head>
<?php $xajax->printJavascript(); ?>
</head>
<body>
<input type="button" onclick="xajax_confirmTest()" value="Confirm"/>
<input type="text" placeholder="Write here first."/>
</body>
</html>
If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.