|
|
|
@ -77,18 +77,18 @@ document.querySelector<HTMLDivElement>($CSS_SELECTOR) // retourne un DIV
|
|
|
|
|
($DATA_NAME in $ELEM.dataset) // retourne un booléen
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
💡 Vous pouvez parcourrir `$ELEM.classList`, `$ELEM.attributes`, et `$ELEM.dataset` :
|
|
|
|
|
💡 Vous pouvez parcourir `$ELEM.classList`, `$ELEM.dataset`, et `$ELEM.getAttributeNames()` :
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
// [JS] Javascript
|
|
|
|
|
for( let name in $ELEM.dataset )
|
|
|
|
|
$ELEM.dataset[name]
|
|
|
|
|
for( let name in $ELEM.getAttributeNames() )
|
|
|
|
|
$ELEM.getAttribute(name)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
# [🐍] Python
|
|
|
|
|
for name in $ELEM.dataset:
|
|
|
|
|
$ELEM.dataset[name]
|
|
|
|
|
for name in $ELEM.getAttributeNames():
|
|
|
|
|
$ELEM.getAttribute(name)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- Modifier le contenu (texte) : `$ELEM.textContent = $STR`
|
|
|
|
@ -106,12 +106,17 @@ for name in $ELEM.dataset:
|
|
|
|
|
```javascript
|
|
|
|
|
// [JS] Javascript
|
|
|
|
|
async query() {
|
|
|
|
|
const anwser = fetch($URL);
|
|
|
|
|
const anwser = await fetch($URL);
|
|
|
|
|
// ou
|
|
|
|
|
const anwser = fetch($URL, {method: "POST", body: $PARAMS);
|
|
|
|
|
const anwser = await fetch($URL, {method: "POST", body: $PARAMS);
|
|
|
|
|
// [🚩] TODO: tester mode: "no-cors"
|
|
|
|
|
|
|
|
|
|
if( ! anwser.ok )
|
|
|
|
|
throw new Error(`${anwser.status}: ${answer.statusText}`);
|
|
|
|
|
|
|
|
|
|
const json = await anwser.json(); // récupérer du JSON
|
|
|
|
|
const text = await anwser.text(); // récupérer du texte
|
|
|
|
|
// autres formats possibles dans la doc.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query();
|
|
|
|
@ -124,8 +129,13 @@ async query():
|
|
|
|
|
# ou
|
|
|
|
|
anwser = fetch($URL, {"method": "POST", "body": $PARAMS)
|
|
|
|
|
# [🚩] TODO: tester mode: "no-cors"
|
|
|
|
|
|
|
|
|
|
if not anwser.ok:
|
|
|
|
|
raise Error(f"{anwser.status}: {answer.statusText}");
|
|
|
|
|
|
|
|
|
|
json = await anwser.json() # récupérer du JSON
|
|
|
|
|
text = await anwser.text() # récupérer du texte
|
|
|
|
|
# autres formats possibles dans la doc.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
aio.run( query() ) # [🚩] TODO: Supplier Pierre pour avoir top-level await.
|
|
|
|
@ -133,8 +143,6 @@ aio.run( query() ) # [🚩] TODO: Supplier Pierre pour avoir top-level await.
|
|
|
|
|
|
|
|
|
|
📖 [Plus d'informations dans la documentation.](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pour construire la chaîne de paramètre :
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
@ -165,11 +173,9 @@ fetch( f"{URL}?{params.toString()}" )
|
|
|
|
|
# serveur
|
|
|
|
|
params = URLSearchParams.new($STR);
|
|
|
|
|
for key in params.keys():
|
|
|
|
|
params.get(key); # retourne undefined si pas trouvé.
|
|
|
|
|
params.get(key) # retourne undefined si pas trouvé.
|
|
|
|
|
|
|
|
|
|
params.has($NAME) # retourne un booléen
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
📖 [Plus d'informations dans la documentation.](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|