How can I refresh the page

How can I refresh the page

ni Sascha Schrader -
Number of replies: 8

I've got my plugin to the point where I can save entries. Now I want to return to the previous page after saving and have the page refresh automatically.

What functions are there to refresh the page? Unfortunately, if I've seen it correctly, the documentation isn't very informative.

Average of ratings: -
In reply to Sascha Schrader

Re: How can I refresh the page

ni Mark Johnson -
Larawan ng Core developers Larawan ng Particularly helpful Moodlers Larawan ng Peer reviewers Larawan ng Plugin developers

If you have a form where you submit an entry, you should have the form processing code save the change, then redirect you back to the previous page using redirect(). The page you are redirecting to should then load with the updated entries, you shouldn't need to refresh the page further.

The exception for this would be if you are using a modal form, and you want the underlying page to load the updated data when you save. If this is what you're doing, I can point you to some examples.

In reply to Mark Johnson

Re: How can I refresh the page

ni Sascha Schrader -

Sorry for not getting back to you until now. I've been sick for a few weeks. Thank you for your info!

I would like to follow your example. So far I've tried the following:

My Button:

<ion-button size="small" class="check" core-site-plugins-call-ws name="local_schultimer_comment_check" goBackOnSuccess="true" (onSuccess)="messagesUpdated()" [params]="{cid: <% id %>, susid: <% susid %>}">

My JavaScript:

const translate = key => this.TranslateService.instant(`plugin.local_schultimer.${key}`);
const observer = this.CoreEventsProvider.on('local_schultimer:messages-updated', () => this.refreshContent());

this.ngOnDestroy = () => observer.off();

and:

this.messagesUpdated = () => this.CoreEventsProvider.trigger('local_schultimer:messages-updated');

I load the files into the file mobile.php in the folders classes->output->mobile.php

return [
            'templates' => [
                [
                    'id' => 'main',
                    'html' => $html,
                ],
            ],
            'javascript' => file_get_contents( __DIR__ . '/../../js/mobile/view_schultimer_list.js' ),
        ];

Can I load a second JavaScript file? This line:

this.messagesUpdated = () => this.CoreEventsProvider.trigger('local_schultimer:messages-updated');

is in another file and is not loaded.

Thank you very much for your help!

In reply to Mark Johnson

Re: How can I refresh the page

ni Sascha Schrader -

Does anyone have a tip for me on how to do the refresh?

In reply to Sascha Schrader

Re: How can I refresh the page

ni Michael Milette -
Larawan ng Core developers Larawan ng Documentation writers Larawan ng Particularly helpful Moodlers Larawan ng Plugin developers Larawan ng Testers Larawan ng Translators

Hi Sascha,

Here are a few suggestions on how to refresh a page:

  1. Press F5, Shift F5, CTRL-F5, or CTRL-R; (not in Moodle App)
  2. Click a link to the same page you are on, adding a datestamp parameter to the URL so that the browser doesn't reload from cache; or
  3. Use JavaScript. Use the same technique as #2 above to avoid cache.

Hope you find this information helpful.

Best regards,

Michael Milette

In reply to Sascha Schrader

Re: How can I refresh the page

ni Angélique Dubois-Chabert -
Hi again Sascha !
Just wanted to inform you that, as I need to reload for all navigation to that page, I decided I can use

const url = 'https://example.com/data' + `?cache_bust=${Date.now()}`;
In reply to Angélique Dubois-Chabert

Re: How can I refresh the page

ni Sascha Schrader -

Hello Angélique, I haven't found a solution yet.
Your approach looks very promising. How exactly did you use the line and where did you use it? What do I have to enter for "example.com/data"? My Moodle URL?