How can I refresh the page

How can I refresh the page

par Sascha Schrader,
Nombre de réponses : 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.

Moyenne des évaluations  -
En réponse à Sascha Schrader

Re: How can I refresh the page

par Mark Johnson,
Avatar Core developers Avatar Particularly helpful Moodlers Avatar Peer reviewers Avatar 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.

Moyenne des évaluations Useful (1)
En réponse à Mark Johnson

Re: How can I refresh the page

par 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!

En réponse à Mark Johnson

Re: How can I refresh the page

par Sascha Schrader,

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

En réponse à Sascha Schrader

Re: How can I refresh the page

par Michael Milette,
Avatar Core developers Avatar Documentation writers Avatar Particularly helpful Moodlers Avatar Plugin developers Avatar Testers Avatar 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

Moyenne des évaluations Useful (1)
En réponse à Sascha Schrader

Re: How can I refresh the page

par Angélique Dubois-Chabert,
Hi Sascha, I am asking myself the same question as my javascript attemps to refresh when going back to my "main" page have failed. Did you find a solution?
En réponse à Sascha Schrader

Re: How can I refresh the page

par 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()}`;
En réponse à Angélique Dubois-Chabert

Re: How can I refresh the page

par 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?