CodeIgniter Forums
How To Use Javascript In CI?? - 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: How To Use Javascript In CI?? (/showthread.php?tid=36528)



How To Use Javascript In CI?? - El Forum - 12-05-2010

[eluser]indigoblue[/eluser]
I want to add javascript alert code like this :
Code:
[removed]
alert("You Dont not Have Permission To Access This Area");
alert("Please Loggin Before...");
[removed]

In a function of my class controller :
Code:
function is_logged_in(){
            $is_logged_in= $this->session->userdata('is_logged_in');
            if (!isset($is_logged_in) || $is_logged_in!=true ){
            /*
                        I wanna place javascript code in this area
                        */
                        redirect('/home/');
            }
        }

But, the problem is that script aren't working??
Thx b4...


How To Use Javascript In CI?? - El Forum - 12-05-2010

[eluser]Twisted1919[/eluser]
1. the isset($is_logged_in) is useles.
2. putting the javascript where you want is WRONG for 2 reasons:
a) the controller NEVER echo's data , the views do that, so you need to load a view to spit those alerts .
b) if you echo something before redirect, you'll end up with an "headers already sent" error .


How To Use Javascript In CI?? - El Forum - 12-06-2010

[eluser]indigoblue[/eluser]
yap. thx.
its work....
problem solved