Welcome Guest, Not a member yet? Register   Sign In
Call External Javascript function using Controller
#1

[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.
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB