CHtml in javascript

Hi,

please how can I use CHtml (or ajax requests, whatever) in a view in javascript?

example:

<script type="text/javascript">

<?php echo CHtml::link(‘Link Text’,array(‘controller/action’)); ?>

</script>

Thanks!

Xsnowy

Your question is not fully clear to me, but if you trying to generate urls you’re on a right way.

Some simple example:




<script type="text/javascript">

    // let's say you're using jQuery

    $(function() {

        // create complete a tag

        var link = '<?php echo CHtml::link('Link Text', array('controller/action')); ?>';


        $.ajax({

            ...

            url: '<?php echo $this->createUrl('controller/action'); /* controller is creating url, but you can use CHtml::normalizeUrl as well */ ?>',

            ...

            success: function(data) {

                $('#someSelector').append(link);

            }

            ...

        });

    });

</script>