Hi all,
I have updated my project to use Yii 1.1.7 and I have noticed that the activeform javascript on ajax validation is using jsonp method as it is adding a ?callback=jQuery… parameter to its ajax requests.
This then breaks the because the return type is plain json generated by CActiveForm::validate($model)
I can make this work by adding.
if (isset($_POST['ajax']) && $_POST['ajax'] === 'mymodel') {
echo $_REQUEST['callback'] . '(';
echo CActiveForm::validate($m);
echo ')';
Yii::app()->end();
}
this wraps the returned json in the callback name like:
jQuery151017513468124114617_1302282226873(
{"AuthItem_name":["An item with the name \"guest\" already exists."]}
)
This then fixes the issue.
But i can’t figure out why it is posting using jsonp. I have noticed that a lot has changed in ajax in the new release of jquery.
Also my CActiveForm widget only has a very small configuration:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'authitem',
'enableAjaxValidation'=>true,
'focus'=>array($model,'name'),
)); ?>
I am not specifying the url so it should use the same as the current page. Very Confused. If anyone knows anything about this would be a big help.