ajax
There are few types of ajax behaviours that are streamlined and eased by @acanto/core-ajax
.
#
Load external resourcesUse this when you want to load thirdy party CSS or JS libraries from publicly available CDN. This is just an alias for the library loadjs
you can follow its documentation
#
Default ajax clientA simple wrapper around atomic a tiny promise based Ajax/HTTP library. By defalt it uses the GET
method. It adds caching by passing a cacheKey
to the options second argument, an ajaxClearCache
is also exposed in order to control the cache clearing.
warning
Caching is opt-in, use it only if you have performance problems and use it with awareness or it might lead to data inconsistencies.
#
Comnunication with the frontendCompared to the default ajax client these helpers simply automatically add the X-CSRF
token needed by Laravel to secure requests.
#
Comnunication with the backendMost of the time it is better to relay the ajax calls to the CMS through your Laravel frontend by exposing an internal fragment route endpoint but if you really need to communicate directly with the backend API you might use these helpers. It allows to automatically interpolate the current locale and it even adds the right authentication headers if the $user
object is exposed to Javascript in your template with <x-data key="user" :value="$user">
although that is not encouraged due to security reasons.