Ajaxcom is JavaScript library which can be used for DOM manipulation called via Ajax from any backend you want. If you are using PHP you can easily use it with Ajaxcom PHP Library. If you use Symfony framework, you can start using Ajaxcom Symfony bundle.
Ajaxcom uses fetch
and Promise
functions. When you have problems with older browsers, please use fetch
and Promise
polyfills.
ajaxcom
library will handle all links except links containing data-ignore-ajaxcom
and links which contains target="_blank"
by default. It automatically handles also all form submissions except forms containing data-ignore-ajaxcom
. When server error occurs the generic message is shown via JavaScript alert.
You can override all of the default options when initializing ajaxcom
library and you can setup few callbacks as well.
You can specify following options when initializing the library - you will pass an object as only argument to ajaxcom()
function:
beforeSend
(function which returns promise) - this function will be called before each Ajax requestsuccess
- (function which returns promise) - this function will be called after the request from backend has been successfulerror
- (simple function) - this function will be called when error occurs on server eg. when server returns non 200 OK responsecomplete
- (simple function) - this function is called afterajaxcom
handles the request eg. after all DOM manipulationslinksSelector
- (string CSS selector) - you can specify which links should be handled viaajaxcom
formsSelector
- (string CSS selector) - you can specify which forms should be handled viaajaxcom
Example:
// initialization
const ajaxcom = require('@everlutionsk/ajaxcom');
ajaxcom.initialize({
complete: function () {
console.log('Yet another page rendered via ajaxcom');
},
error: function (e) {
console.error(e);
}
});
// usage of Ajaxcom request
ajaxcom.fetch({
url: 'https://some.url',
method: 'POST', // defaults to 'GET'
body: JSON.stringify({ data: 'you', want: 'to', pass: 'to backend' }) // optional
// optionally you can provide callbacks such as beforeSend, success, error and complete
});
Install the latest yarn.
Install all dependencies via yarn:
yarn install
yarn build
yarn watch
yarn checkup
npm login
npm version patch|minor|major
npm publish . --access public