How to do a Full Page Reload After Delete or Update For GroceryCRUD Enterprise Version: 2.7.9?

Does anyone know how to do a full page reload for GroceryCRUD Enterprise Version: 2.7.9?

I have tried the following:

  1. Use of header(“Location:”)
  2. Use of redirect(“controller/functionname”)
  3. Use of echo to add javascript that reloads the page:
    echo '<script>
            top.window.location=http://mysite/somepage.php";
            die;
          </script>';

Thank you in advance!

Hello @larasmith ,

The code that you are trying to apply it is blocked by the JavaScript that we use as this can cause XSS attacks. On the other side, you can use the JavaScript callbacks that we have here: unsetAutoloadJavaScript | Grocery CRUD

For example:

$(document).ready(function () {
    $('.gc-container').groceryCrud({
        callbackAfterUpdate: function (currentForm) {
            window.location = 'http://mysite/somepage.php';
        },
    );
});

Please keep in mind that if you upgrade to the latest Grocery CRUD Enterprise, you can also use the RedirectResponse class as per documentation here: Full Page Redirection | Grocery CRUD

Regards
Johnny

1 Like

Thank you for this response :blush:
I was not able to apply it though because I already have a workaround:

      $crud->callbackAfterInsert(function ($stateParameters) {
          $this->m_ImportDatabase->addHistory($stateParameters->insertId);

          $msg = '<script>
                    $(document).ready(function () {
                      $(".gc-error-modal-dialog").hide();
                    });
                    
                    top.location.reload();
                  </script>';

          return (new \GroceryCrud\Core\Error\ErrorMessage())->setMessage($msg);
      });  

In the script, I hide the container of the error dialog box then triggered the reload.
It’s not proper though but does the work :sweat_smile:

1 Like

Oh god, you literally hacked the system and find something that I haven’t thought :slight_smile:

1 Like

To perform a full page reload in GroceryCRUD Enterprise Version 2.7.9, you can use the following code:

phpCopy code

redirect(current_url(), 'refresh');

This code will redirect the current URL to itself with the ‘refresh’ parameter, which will reload the page. The current_url() function is a helper function provided by CodeIgniter, which returns the current URL.

Here is an example of how you can use this code:

phpCopy code

public function my_function()
{
    // Some code here...
    
    redirect(current_url(), 'refresh');
}

You can also use the header() function to perform a full page reload, like this:

phpCopy code

header("Location: " . current_url());

This will redirect the current URL to itself using the Location header, which will cause the browser to reload the page.

I hope this helps! Let me know if you have any further questions.

The above code helped me solve the problem. Thank you very much.