hypejunction / hypeajax
此包已被放弃,不再维护。未建议替代包。
Ajax 工具
1.2.1
2018-08-21 13:55 UTC
Requires
- php: >=7.0
- composer/installers: ~1.0
This package is not auto-updated.
Last update: 2020-02-29 14:13:18 UTC
README
Ajax 请求工具
- 延迟视图渲染
用法
延迟视图渲染
要延迟视图渲染,只需将 'deferred' => true
添加到视图变量中。
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 表单
ajax/Form
AMD 模块可用于链式处理基于 promise 的提交回调并通过 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(); ajax.post('somewhere').done(resolve).fail(reject); }) form.onSubmit(function(resolve, reject) { console.log('hello'); resolve(); }); // 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) { console.log(data); require('elgg/lightbox', function(lightbox) { lightbox.close(); }); $('.my-list').refresh(); }); // You can also add your own error handler form.onError(function(error) { console.log(error); });