tags:

views:

53

answers:

2

Hi, I need to call a javascript function from my controller in codeigniter.It is possible in codeigniter ? Problem Details My javascript file contains

function debugOutput(msg) {
 alert (msg);
}

and also I need to call it from my controller.

I done it as follows.

<?php
function check()
{
header('Content-type: application/x-javascript');
// body here
}
?>
function execute() {
    debugOutput("&lt;?php echo 'test'; ?&gt;");
}
execute();

But it is not working.Please help me to solve it.

A: 

For one, you would need to surround the call with <script> tags:

<script type="text/javascript">
 function execute() {
 ...
 }
</script>
Justin Ethier
A: 

Finally I got the answer.Here I am sharing that answer;

<?php function check(){
{header('Content-type: application/x-javascript');?>
        function execute() {
        showName(<?php echo 'ajithperuva';?>);
        }
        execute();
    <?php
    }

This script will invoke an external javascript function showName(). Thanks for all help me in my trouble.

Ajith