yii-ajax simplify your ajax requests

  1. Features
  2. Instalation
  3. Usage
  4. Resources

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

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

1 0
4 followers
0 downloads
Yii Version: Unknown
License: BSD-2-Clause
Category: Networking
Developed by: once
Created on: Jan 30, 2014
Last updated: 10 years ago

Related Extensions