请教在CONTROLLER中JS跳转问题
本帖最后由 gqhk 于 2010-4-7 13:31 编辑在CONTROLLER层 先进行JS alert('提示'),然后进行跳转window.location.href="<?php echo site_url('controller/function')?>" 不能正确跳转,只能输入绝对路径window.location.href='http://localhost/index.php/controller/function' 只有这样才能正常跳转,请问如何用base_url()或site_url()结合起来实现跳转呢? 是否已經加載url輔助函數
$this->load->helper('url'); $autoload['helper'] = array('url'); 这个是全局调用,在CONTROLLER里不知道为什么不能把SITE_URL放到JS里进行跳转,继续求助。。 这里JS一般指的是客户端,因此,你在里面要使用Site_url的话,应放在“<?php xxxxxxx ?>”之中。 site_url()是CI语法,当然是写在PHP内,服务器执行完,将解析的结果返回到客户端继续执行JS,只是返回的SITE_URL()依然是字符串,没有解析成文件路径,求教各路高手! 能把这部分的源码帖出来吗,估计源码有问题。 <?php
echo "<script>alert('xxx');window.location.href=\"<?php echo site_url('c/f');?>\";</script>";
?>
=========================================
<?php
echo "<script>alert('xxx');window.location.href=\"echo site_url('c/f')\";</script>";
?>
这二种写法都不行,输入地址栏依然是site_url('c/f') 没有进行解析。。 郁闷了 <?php ?>或echo 不支持嵌套
請這樣使用
<script>alert('xxx');window.location.href="<?php echo site_url('c/f'); ?>";</script>
或
<?php
echo '<script>alert("xxx");window.location.href="' , site_url('c/f') , '</script>';
?> 多谢楼上指点,已经搞定了!:lol window.location.href改成window.location吧,你那个就是IE认得
页:
[1]
2