gqhk 发表于 2010-4-6 16:45:57

请教在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()结合起来实现跳转呢?

huboo82 发表于 2010-4-6 18:34:24

是否已經加載url輔助函數
$this->load->helper('url');

gqhk 发表于 2010-4-6 21:11:59

$autoload['helper'] = array('url'); 这个是全局调用,在CONTROLLER里不知道为什么不能把SITE_URL放到JS里进行跳转,继续求助。。

da123 发表于 2010-4-6 22:29:37

这里JS一般指的是客户端,因此,你在里面要使用Site_url的话,应放在“<?php xxxxxxx ?>”之中。

gqhk 发表于 2010-4-6 22:57:23

site_url()是CI语法,当然是写在PHP内,服务器执行完,将解析的结果返回到客户端继续执行JS,只是返回的SITE_URL()依然是字符串,没有解析成文件路径,求教各路高手!

da123 发表于 2010-4-6 23:42:35

能把这部分的源码帖出来吗,估计源码有问题。

gqhk 发表于 2010-4-7 09:00:43

<?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') 没有进行解析。。 郁闷了

huboo82 发表于 2010-4-7 09:18:30

<?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>';
?>

gqhk 发表于 2010-4-7 13:30:51

多谢楼上指点,已经搞定了!:lol

jeongee 发表于 2010-4-7 13:33:57

window.location.href改成window.location吧,你那个就是IE认得
页: [1] 2
查看完整版本: 请教在CONTROLLER中JS跳转问题