diff options
Diffstat (limited to 'views/mods/mod_revocation/page_form.phtml')
| -rw-r--r-- | views/mods/mod_revocation/page_form.phtml | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/views/mods/mod_revocation/page_form.phtml b/views/mods/mod_revocation/page_form.phtml index 6dda801..f7849ff 100644 --- a/views/mods/mod_revocation/page_form.phtml +++ b/views/mods/mod_revocation/page_form.phtml @@ -112,7 +112,8 @@ const form = document.getElementById('wpsg_revocation_page_form'); if (form === null) return; - const nonce = '<?php echo \wp_create_nonce('wpsg_mod_revocation_nonce'); ?>'; + // Kann aus dem Seiten-Cache kommen; ist sie abgelaufen, schickt der Server eine frische mit (K48) + let nonce = <?php echo \wp_json_encode(\wp_create_nonce('wpsg_mod_revocation_nonce')); ?>; const endpoint = '<?php echo \admin_url('admin-ajax.php'); ?>?action=wpsg_mod_revocation&do=ajaxDialogSubmit'; const msg = document.getElementById('wpsg_revocation_page_msg'); const button = form.querySelector('.wpsg_revocation_page_submit'); @@ -155,11 +156,27 @@ const form_data = formDataToObject(new FormData(form)); - fetch(endpoint, { + const post = retry => fetch(endpoint, { method: 'POST', + credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ nonce: nonce, form_data: form_data }) - }).then(res => res.json()).then(res => { + }).then(res => res.json().then(json => { + + if (res.status === 403 && retry && (json?.data?.code ?? '') === 'wpsg_nonce') { + + nonce = json.data.nonce; + return post(false); + + } + + if (!res.ok) throw new Error(res.status); + + return json; + + })); + + post(true).then(res => { button.disabled = false; |
