5 ms·
Clicking on buttons triggers Ajax request via stimulus controller (this takes care of CSRF and session) and fetches just the required HTML from route and append
by pvsukale3 5y ago
Clicking on buttons triggers Ajax request via stimulus controller (this takes care of CSRF and session) and fetches just the required HTML from route and appends using innerHTML (https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML https://developer.mozilla.org/en-US/docs/Web/API/Element/inn...).
an example following is an event listener in a JS controller.
openAddJob(event) {
this.openDialogAddClasses();
this.modalPanelTarget.innerHTML = MODAL_SPINNER_HTML;
$.ajax({
type: "GET",
url: `/job_items/new_form`,
success: function (repsonse) {
this.modalPanelTarget.innerHTML = repsonse;
}.bind(this),
error: function (repsonse) {},
});
}
Currently there is a lot of scope for DRY a lot of things in the app but will be doing that once I have more feature tests coverage.
- joelbluminator 5y agoOK you kinda roll your own solution here, looks easy enough.