Search code examples
ajaxyii

Yii - Yii::app()->request->isAjaxRequest?


I'm a little bit confused about isAjaxRequest. Why and When should I use this? Is this important when data sent by a jQuery AJAX submit form?


Solution

  • You could use this method in order to test whether the controller was invoked with an AJAX request or not. This might allow you to do some adaptive rendering. For example if it wasn't an AJAX request return HTML, if it is an AJAX request return JSON.