-
Notifications
You must be signed in to change notification settings - Fork 20
Development: AJAX API
Sami Mokaddem edited this page Jan 12, 2021
·
7 revisions
The api-helper.js Provides helpers to perform AJAX requests against cerebrate. It can provide feedback about the progress of the operation to the user and reload part of the page.
Function commonly used throughout the application
-
quickFetchURLsimply fetches the remote
// quickFetchURL(url, options={})
AJAXApi.quickFetchURL('/users/index').then(text => {
console.log(text)
})-
quickFetchJSONsimply fetches the remote JSON
// quickFetchJSON(url, options={})
AJAXApi.quickFetchURL('/users/view/1').then(json => {
console.log(json)
})-
quickFetchFormfetches the HTML at the provided URL, then extract the form. Resolves to the HTMLFormElement if successful
// quickFetchForm(url, options={})
AJAXApi.quickFetchForm('/users/add').then(formElement => {
document.body.append(formElement)
})-
quickPostFormPOST a form, dataToMerge can be used to modify form values on-the-fly
// quickPostForm(form, dataToMerge={}, options={})
AJAXApi.quickPostForm(form, {uuid: genUUID()}).then(json => {
console.log(json)
})-
quickFetchAndPostFormFetch a form, dataToMerge can be used to modify form values on-the-fly and then POST it
// quickFetchAndPostForm(url, dataToMerge={}, options={})
AJAXApi.quickFetchAndPostForm('/users/toggle/1/enabled).then(json => {
console.log(json)
})