I've previously created a question where I wanted to understand principles of work with ajax in Yii. So, I'm trying to implement an answer. I'v created controller and placed in into controllers directory:
<?php
class AjaxController extends CController
{
public function actionDoThing()
{
// Get request object
$request = Yii::app()->request;
// Check if request is acceptable
if ($request->isPost && $request->isAjaxRequest)
{
echo CJSON::encode(array('hello'=>'world'));
}
// else
// {
// throw new CHttpException(403);
// }
}
}
?>
Also I have this fragment with script in my view.
<script>
$(document).on('click','div.lessonDiv', function() {
$.ajax({
type: "POST",
url: <?php /*Also I tried just DoThing instead of actionDoThing, this doesn't work*/echo $this->createUrl('AjaxController/actionDoThing'); ?>,
success: function(data, textStatus, jqXHR)
{
console.log(data);
}
});
});
</script>
Dunno what's wrong, but console says:
Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'actionDoThing'
Where am I wrong now?