mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 23:35:13 +00:00
Merge pull request #759 from arcanemachine/patch-1
add instructions for using `htmx.ajax()` with a callback
This commit is contained in:
commit
bfacab1338
@ -28,7 +28,7 @@ This method adds a class to the given element.
|
|||||||
|
|
||||||
### <a name="ajax"></a> Method - [`htmx.ajax()`](#ajax)
|
### <a name="ajax"></a> Method - [`htmx.ajax()`](#ajax)
|
||||||
|
|
||||||
Issues an htmx-style AJAX request
|
Issues an htmx-style AJAX request. This method returns a Promise, so a callback can be executed after the content has been inserted into the DOM.
|
||||||
|
|
||||||
##### Parameters
|
##### Parameters
|
||||||
|
|
||||||
@ -60,6 +60,13 @@ or
|
|||||||
```js
|
```js
|
||||||
// issue a GET to /example and put the response HTML into #myDiv
|
// issue a GET to /example and put the response HTML into #myDiv
|
||||||
htmx.ajax('GET', '/example', '#myDiv')
|
htmx.ajax('GET', '/example', '#myDiv')
|
||||||
|
|
||||||
|
// execute some code after the content has been inserted into the DOM
|
||||||
|
htmx.ajax('GET', '/example', '#myDiv').then(() => {
|
||||||
|
// this code will be executed after the 'htmx:afterOnLoad' event,
|
||||||
|
// and before the 'htmx:xhr:loadend' event
|
||||||
|
console.log('Content inserted successfully!');
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### <a name="closest"></a> Method - [`htmx.closest()`](#closest)
|
### <a name="closest"></a> Method - [`htmx.closest()`](#closest)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user