Javascript 如何在CodeIgniter中重定向?
我正在尝试使用以下代码重定向到特定页面:Javascript 如何在CodeIgniter中重定向?,javascript,php,jquery,codeigniter,Javascript,Php,Jquery,Codeigniter,我正在尝试使用以下代码重定向到特定页面: window.location.href="'<?php echo base_url() ?>'/index.php/user/view_cart/viewCart"; 我得到的输出是 The URI you submitted has disallowed characters. 这是我的cuurent页面: http://localhost/CI/index.php/user/view_available_books/viewAvai
window.location.href="'<?php echo base_url() ?>'/index.php/user/view_cart/viewCart";
我得到的输出是
The URI you submitted has disallowed characters.
这是我的cuurent页面:
http://localhost/CI/index.php/user/view_available_books/viewAvailableBooks/
这就是它重定向的方式:
http://localhost/CI/index.php/user/view_available_books/viewAvailableBooks/'%3C?php%20echo%20base_url()%20?%3E%27/index.php/user/view_cart/viewCart
它在重定向时也会获取当前页面的url。有什么解决办法吗?从您的上述陈述中删除
单引号
<script>window.location.href="<?php echo base_url(); ?>/index.php/user/view_cart/viewCart";</script>
JS文件无法处理PHP。相反,您可以尝试将JS更改为PHP文件,然后尝试以下操作:
从以下位置重命名js文件:
<script src="yourExternalJsFile.js"></script>
致:
在php文件中包含如下脚本:
<?php header("Content-type: application/x-javascript");?>
window.location.href="'<?php echo base_url() ?>'/index.php/user/view_cart/viewCart";
window.location.href=“”/index.php/user/view\u cart/viewCart”;
您可以在配置文件中存在的允许的uri字符中添加不允许的字符。
在cofig文件中
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-=';
但是在你的例子中,你添加了单引号,这是错误的,你必须删除单引号。这段代码是在js文件还是php文件中?在外部js文件中,php将不起作用。你需要将它放在php文件中,并删除单引号。PP在js文件1中不起作用。外部js无法执行php,2。这是javascript中的重定向,而不是CI。删除单引号非常有效。如果你能解释为什么单引号会导致这个问题,那就太好了。非常感谢:)
<script src="yourExternalJsFile.php"></script>
<?php header("Content-type: application/x-javascript");?>
window.location.href="'<?php echo base_url() ?>'/index.php/user/view_cart/viewCart";
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-=';