Ajax utilities

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0


v4.0 2021-10-17 15:04 UTC

This package is not auto-updated.

Last update: 2024-02-19 23:37:48 UTC


Elgg 4.0

Utilities for AJAX requests

  • Deferred view rendering


Deferred view rendering

To defer view rendering, simply add 'deferred' => true to view vars.

echo elgg_view('my_view', [
	// tells the view system to defer view render
	'deferred' => true,
	// if set to false, placeholder will not be rendered
	// if set to a value, that value will be used as the placeholder
	// if not set, default ajax loader will be used
	'placeholder' => false,
	// you can pass other view vars, as you would with normal views
	// various Elgg data will be serialized and available to the deferred view
	// some of the values may need to be wrapped into a Serializable instance
	'entity' => get_entity(123),
	'user' => get_user(234),

Ajax Forms

ajax/Form AMD module can be used to chain promise-based submit callbacks and submit the form via Ajax.

var Form = require('ajax/Form');
var form = new Form('.my-form');
var Ajax = require('elgg/Ajax');

form.onSubmit(function(resolve, reject) {
	// execute a long running script, e.g. validate fields via ajax
	var ajax = new Ajax();'somewhere').done(resolve).fail(reject);

form.onSubmit(function(resolve, reject) {

// By default, once all promises are resolved, the form will be submitted via ajax,
// and the user will be forwarded to the URL specified by the response
// You can however register custom success callbacks to prevent redirection

form.onSuccess(function(data) {
	require('elgg/lightbox', function(lightbox) {

// You can also add your own error handler

form.onError(function(error) {