I am trying to write a Yii action that is called from d3.js.
The javascript in d3.js is:
d3.json(vr, function(error,j) { // get the json object from yii.
if (error) {showerror(error);return}
askquestions(...);
});
}
The page is rendered with Yii. I pass the variable vr in the view with:
Yii::app()->clientScript->registerScript('uniqueid', 'var vr = "'.CHtml::encode($message->kiesprojectvragenurl).'";' ,CClientScript::POS_HEAD);
This generates the javascript code in the view:
<script type="text/javascript">
/*<![CDATA[*/
var vr = "/index.php?r=Kiesproject/kp&projectid=9206";
/*]]>*/
</script>
KiesprojectController.php has the action:
public function actionKp($projectid)
{
$data = some sql;
return json_encode($data);
}
However, if I call the url from d3.js the debugger gives error 400 Bad request.
Calling the action with
$message->jsondata = $this->actionKp($message->projectid);
renders the jsondata fine.
I do have two questions:
-
Is this the correct way to get data into d3.js from Yii?
-
What generates error 400? I can not find the error.
Thanks for your time.
Ar