[英]Execute Java script code from CodeIgniter Controller
In my CodeIgniter
controller every Ajax
request checks the token I Passed. 在我的
CodeIgniter
控制器中,每个Ajax
请求都会检查我传递的令牌。 If any thing happens wrong I wrote a controller function to destroy all session and logout 如果发生任何错误,我编写了一个控制器函数来销毁所有会话并注销
'redirect('main/logincontent/load_logout');'
In load_logout function 在load_logout函数中
function load_logout() { 函数load_logout(){
echo "<script>var c=confirm('do you want to continue?');
if(c==true)
{
}
else
{</script>";
$this -> session -> sess_destroy();
echo "<script>window.parent.location.href ='" . base_url() . "';
}</script>";
}
I tried put a confirm box at the beginning of the function load_logout()
. 我尝试将确认框放在函数
load_logout()
的开头。 Based on confirm box result user can decide whether to destroy session
and logout or stay Online
. 根据确认框结果,用户可以决定是
destroy session
并注销还是stay Online
。
But it is not working!!! 但这不起作用!!!
Any help would be appreciated. 任何帮助,将不胜感激。
you don't need to close script tag each time, try this 您不需要每次都关闭脚本标签,请尝试此操作
echo "<script>var c=confirm('do you want to continue?');
if(c==true){}else{";
$this -> session -> sess_destroy();
echo "window.parent.location.href ='" . base_url() . "';
}</script>";
but it is impossible to destroy session from client side. 但是不可能从客户端破坏会话。 What you are doing here is just printing these details in client browser.
您在这里所做的只是在客户端浏览器中打印这些详细信息。 But $this -> session -> sess_destroy();
但是$ this-> session-> sess_destroy(); will not work in browser, because it is server code.
在浏览器中将无法使用,因为它是服务器代码。 You need to add a route to destroy session and call that.
您需要添加一条路由来销毁会话并调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.