yii-ajax

simplify your ajax requests
4 followers

Features

  • 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

Instalation

  • git clone https://github.com/oncesk/yii-ajax.git
  • using archive: download archive and unpack it into application.ext directory

Usage

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',
  dataType : 'json',
  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();
}

Resources

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet