[size=6]
Features
[/size]
[list=1]
[*]global response object in PHP -> YiiAjax::getResponse() // return object which implments ArrayAccess and Iterator interfaces
[*]with AjaxEvent you can send any event with any data from PHP and catch it in javascript
[*]AjaxJqueryReplaceWith automatically replace content in provided selector
[*]AjaxJqueryHtml similar to AjaxJqueryReplaceWith but use jquery html method
[/list]
[url=https://github.com/oncesk/yii-ajax]
See more on Github
[/url]
[size=6]
Example
[/size]
In Javascript:
// triggered before invoke update.summary
YiiAjax.on('before:update.summary', function (response, chain) {
// here you can break next execution or do some actions
console.log('before invoke update.summary');
});
YiiAjax.on('update.summary', function (response, chain) {
console.log('update.summary is invoked');
console.log('totalPrice is: ' + response.totalPrice);
// do any action
});
YiiAjax.on('after:update.summary', function (response) {
console.log('after update.summary');
});
YiiAjax.ajax({
url : '/site/ajaxExample',
success : function (response) {
console.log(response.reason);
}
});
In PHP
public function actionAjaxExample() {
new AjaxEvent('update.summary', array(
'totalPrice' => 500,
'deliveryPrice' => 30
));
$response = YiiAjax::getResponse();
$response['success'] = false;
$response['reason'] = 'Some reason';
Yii::app()->end();
}