javascript:ajax
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
javascript:ajax [15/02/2021 16:39] – Externe Bearbeitung 127.0.0.1 | javascript:ajax [15/02/2021 17:17] (aktuell) – Manuel | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== | + | ====== |
- | Zusatzinformationen zu JInput - Joomla-Klasse, | ||
- | Offizielle Doku: https:// | ||
- | ===== Klasse ===== | ||
- | So wird die Klasse aufgerufen: | + | ===== Fetch ===== |
- | <file php> | + | Einen asynchronen Request über Javascript machen mithilfe der Fetch. |
- | use Joomla\CMS\Factory; | + | |
- | $input = Factory:: | + | |
- | // equivalent of the older format $input = JFactory:: | + | |
- | </ | + | |
- | ==== Eine bestimmte Variable ==== | + | Docs: https:// |
- | <file php> | + | === Variablen |
- | $name = $input-> | + | |
- | </file> | + | |
- | ==== Mehrere bestimmte Variablen ==== | + | <file javascript> |
+ | let formData | ||
+ | formData.append(' | ||
+ | formData.append(' | ||
- | <file php> | + | let parameters |
- | $name = $input-> | + | method: ' |
- | </ | + | mode: 'same-origin', // no-cors, *cors, same-origin |
+ | cache: | ||
+ | headers: {' | ||
+ | redirect: | ||
+ | referrerPolicy: | ||
+ | body: formData // JSON.stringify(data) // (body data type must match " | ||
+ | }; | ||
- | ==== Variablen aus einem Joomla-Formular (JForm) ==== | + | let url_ident |
- | + | ||
- | < | + | |
- | $name = $input-> | + | |
</ | </ | ||
- | ==== Eine bestimmte GET-Variable ==== | + | === Request |
- | < | + | < |
- | $name = $input-> | + | async function postData(url, |
- | </file> | + | const response |
+ | if (!response.ok) { | ||
+ | if (response.status == 0) { | ||
+ | // on network error | ||
+ | console.log(" | ||
+ | } | ||
+ | } else { | ||
+ | | ||
+ | return response.json(); | ||
+ | } | ||
+ | }; | ||
- | ==== Alle vorhandenen Variablen ==== | + | postData(url_ident, |
- | + | .then(res | |
- | <file php> | + | let data = res.data; |
- | $name = $input-> | + | console.log(data); |
+ | } | ||
+ | }); | ||
</ | </ | ||
- |
javascript/ajax.1613403543.txt.gz · Zuletzt geändert: 15/02/2021 16:39 von 127.0.0.1