I have an AJAX call in my view to an action in my controller. However, I always get an Error 400. Below is the code for my AJAX call:
$.ajax({
cache: false,
url: '/dummy/index.php/module/controller/checkCross',
dataType: 'json',
type: 'POST',
data : {"male":parents[0],"female":parents[1]},
success: function(result){
alert(result);
}
});
Below is the code in the controller:
public function actionCheckCross(){
if(Yii::app()->request->isPostRequest) { // check if POST
$flag = CrossingMatrix::model()->checkParentsIfCrossed($_POST['male'],$_POST['female']);
if($flag){
return true;
}
else{
return false;
}
} else { // direct URL request will be GET, so show error
throw new CHttpException(400, Yii::t('app', 'Direct access is not allowed.'));
}
}
Any ideas?