A custom element to enable partial page updates via AJAX.
<ajax-fragment target="posts">
<form method="get" data-use-ajax>
<!-- Form HTML omitted for brevity -->
</form>
</ajax-fragment>
<ajax-fragment id="posts">
<ol>
<li><!-- Post HTML omitted for brevity --></li>
<li><!-- Post HTML omitted for brevity --></li>
<li><!-- Post HTML omitted for brevity --></li>
</ol>
</ajax-fragment>- Use the
targetattribute to reference another fragment or element in the same document.
Choose one of the following options:
- Install via npm:
npm install @dweidner/ajax-fragment-element - Download the source manually from GitHub into your project.
- Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)
Make sure you include the <script> in your project (choose one of these):
<!-- Host yourself -->
<script type="module" src="ajax-fragment-element.js"></script><!-- 3rd party CDN, not recommended for production use -->
<script type="module" src="https://www.unpkg.com/@dweidner/ajax-fragment-element@1.0.0"></script><!-- 3rd party CDN, not recommended for production use -->
<script type="module" src="https://esm.sh/@dweidner/ajax-fragment-element@1.0.0"></script>- Load a partial page fragment via AJAX
- Customizable morphing strategy
- Customizable Content Security Policy