pp-after-request

The pp-after-request attribute is used to wait for the PHP function to execute and return the response. It allows you to set the response to targets without triggering a full page rendering. It is commonly used to update specific elements on the page without reloading the entire page, such as updating a shopping cart or afterRequesting real-time notifications.

The pp-after-request="JSfunction" attribute can be a string, a JavaScript function to execute directly, or a JSON object with the following properties: {'targets': [{'element_id': 'target_id', 'method': 'replace'}]}. For example, you can use pp-after-request="welcomeModal.showModal()" to show a modal after the PHP function is executed.

NOTE: If the pp-after-request="@close" attribute is used, the PHP function will execute and return the response without triggering a page reload. To achieve this, set the pp-after-request attribute to "@close".

Example Usage

<?php

  function handlerClick()
  {
      return ['isValid' => true];
  }
  
  ?>
  
  <button onclick="handlerClick" pp-after-request="handlerIsValid">Valid</button>
  
  <script>
      function handlerIsValid(data) {
          if (data.response.isValid) {
              alert('Valid');
          } else {
              alert('Invalid');
          }
      }
  </script>

Note: The pp-after-request attribute is used to target only the PHP function and the target element, without triggering a full page rendering. It is commonly used to update specific elements on the page without reloading the entire page. This attribute allows the PHP function to execute and return a value, which can then be handled in the JavaScript function.