Changes
Title
unchanged
Reliable Alternative For Yii::app()->request->isAjaxRequest AND Adding Data To Ajax Form With JS
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
alternative, reliable alternative, isAjaxRequest, ajax form data, javascript, jquery, add form data
Content
changed
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'.[...]