Reliable Alternative For Yii::app()->request->isAjaxRequest AND Adding Data To Ajax Form With JS

Comparing #9 with #10

Revision #10 was created by ibo_s ibo_s on Oct 9, 2011, 5:45:16 PM.

summary

Content

In this How-To I'll show you: 1.) A reliable alternative to Yii::app()->request->isAjaxRequest (because it doesn't work for everybody and it's not reliable) 2.) How to add extra data to a formn ajax-request without setting a hiddenField in your form, only using javascript, before sending the form.

Here you can read more about why 'isAjaxRequest' isn't reliable:
[http://www.yiiframework.com/forum/index.php?/topic/4945-yiiapp-request-isajaxrequest/](http://www.yiiframework.com/forum/index.php?/topic/4945-yiiapp-request-isajaxrequest/ "yii app request isAjaxRequest")

The main idea is adding a parameter to our request which tells us if the current request is an ajax-request or not. So if you work with an ajax form, you would for example add a hiddenField named 'isAjaxRequest' and set the value to '1'.
[...]