Merge pull request #759 from arcanemachine/patch-1

add instructions for using `htmx.ajax()` with a callback
This commit is contained in:
1cg 2022-01-14 10:57:19 -07:00 committed by GitHub
commit bfacab1338
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,7 +28,7 @@ This method adds a class to the given element.
### <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
@ -60,6 +60,13 @@ or
```js
// issue a GET to /example and put the response HTML into #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)