jaxon-php / jaxon-js

The Jaxon javascript library https://www.jaxon-php.org.
BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

Jaxon v4 stops processing if a synchronous function returns an empty response #32

Closed walmartshopper closed 1 month ago

walmartshopper commented 2 months ago

Sometimes when I call a jaxon function, if certain conditions are not met, I want to simply return an empty response without adding any commands. This works fine for asynchronous functions. However if I try to return an empty response from a synchronous function, jaxon will completely stop processing all other responses until the page is refreshed. There are no error messages in the developer console. The debug dialog stops on the "PROCESSING" step but with no errors displayed. I'm not sure if this is a bug or expected behavior, but in xajax and jaxon up to v3, synchronous functions returning empty responses did not cause any issues.

As a workaround, I am assigning an empty string to an empty div on the page, and having that one dummy command in the response fixes the issue.

Code to reproduce is below. If you click the Alert button first it will work. But once you click the Save button and the synchronous function returns an empty response, both buttons will stop working until you refresh the page.

<?php
  require_once("./vendor/autoload.php");
  use Jaxon\Jaxon;
  use function Jaxon\jaxon;

  $jaxon = jaxon();
  $jaxon->register(Jaxon::CALLABLE_FUNCTION, 'save', array("mode"=>"'synchronous'"));
  $jaxon->register(Jaxon::CALLABLE_FUNCTION, 'alert');
  if($jaxon->canProcessRequest())
    $jaxon->processRequest();

  function save()
  {
    $response = jaxon()->newResponse();
    //do nothing and return an empty response
    return $response;
  }

  function alert()
  {
    $response = jaxon()->newResponse();
    $response->alert('test alert');
    return $response;
  }
?>

<html>
<head>
<?php print $jaxon->getScript(true, true); ?>
</head>
<body>
  <button type='button' onclick="jaxon_save();">Save</button>
  <button type='button' onclick="jaxon_alert();">Alert</button>
</body>
</html>
feuzeu commented 2 months ago

Fixed in release 4.0.7.