view页面写js

<?php

$js = <<<JS
        url2 = "index.php?r=yourcontroller/index";
        org = new Object();
        org["userid"]=1;
        $("#sendbtn").click(function()
            {
                    alert("ajax");
                    $.ajax(
                                {
                                    url:url2,
                                    type:'post',
                                    //headers:{'X-CSRF-TOKEN':_rsf},
                                    data:org,
                                    success:function(data){alert("sucess2:"+data);},

                                    error: function (jqXHR, textStatus, errorThrown) {
                                            alert(jqXHR.status+textStatus);

                                    }
                                }
                            );


            });
JS;
    $this->registerJs($js);


?>