0

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.

1
  • I'm not exactly sure what do you want to do here. Also formatting your code a little would help a lot for readability and understanding. Commented May 17, 2010 at 9:01

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.