
FetchIt
Lightweight AJAX form submission in MODX via the Fetch API on top of FormIt or a custom snippet


jGrowl: jQuery plugin for toasts. It shipped with AjaxForm in the past.
The library requires jQuery.
Load jQuery first, then jGrowl. Define themes in CSS for success/error types:
<!-- jQuery -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" defer></script>
<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/jgrowl@1/jquery.jgrowl.min.js" defer></script>
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/jgrowl@1/jquery.jgrowl.min.css" rel="stylesheet">
<style>
.custom-success { background: green; }
.custom-error { background: red; }
</style>Set FetchIt.Message:
document.addEventListener('DOMContentLoaded', () => {
FetchIt.Message = {
success(message) {
$.jGrowl(message, { theme: 'custom-success' })
},
error(message) {
$.jGrowl(message, { theme: 'custom-error' })
},
}
})In a separate file with defer (after the FetchIt script), skip the DOMContentLoaded wrapper:
FetchIt.Message = {
success(message) {
$.jGrowl(message, { theme: 'custom-success' })
},
error(message) {
$.jGrowl(message, { theme: 'custom-error' })
},
}Skip jGrowl if jQuery is not on the site: load it only when jQuery is already in use. Form blocks [data-success] and [data-validation-error] work alongside toasts. Skip Message if you only need those blocks. Selectors: documentation.