CodeIgniter Forums
Call External Javascript function using Controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Call External Javascript function using Controller (/showthread.php?tid=30489)



Call External Javascript function using Controller - El Forum - 05-17-2010

[eluser]Unknown[/eluser]
Hi,
I need to call a javascript function from my controller.It is possible in codeigniter ?
Problem Details
My javascript file contains
Code:
function debugOutput(msg) {
    alert (msg);
}
and also I need to call it from my controller.

I done it as follows.
Code:
<?php
function check()
{
header('Content-type: application/x-javascript');
// body here
}
?>
function execute() {
    debugOutput("<?php echo 'test'; ?>");
}
execute();

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


Call External Javascript function using Controller - El Forum - 05-19-2010

[eluser]Unknown[/eluser]
Finally I got the answer.Here I am sharing that answer;

Code:
<?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.