douzhangkui2467 2010-01-24 17:59
浏览 46

Codeigniter和jQuery css切换器

I have been following a tutorial on creating a style switcher with PHP and jQuery, now in the tutorial the PHP function uses get data, which is not available in codeigniter, I was hoping someone would be able to help me tidy up my sorry attempt?

My PHP function

    function setBackground() {
    $style = $this->uri->segment(3);
    setcookie("style", $style, time() + (60*60*24*30));
    echo $style;
}

My HTML and jquery call

<ul id="options">
    <li><a class="option" href="<?php echo base_url();?>welcome/setBackground/red">Red</a></li>
    <li><a class="option" href="<?php echo base_url();?>welcome/setBackground/green">Green</a></li>
</ul>
<script type="text/javascript">
$('a.option').styleSwitcher(); // calling the plugin
</script>

The jQuery plugin

jQuery.fn.styleSwitcher = function(){
$(this).click(function(){
    loadStyleSheet(this);
    return false;
});
function loadStyleSheet(obj) {
    $('body').append('<div id="overlay" />');
    $('body').css({height:'100%'});
    $('#overlay')
        .css({
            display: 'none',
            position: 'absolute',
            top:0,
            left: 0,
            width: '100%',
            height: '100%',
            zIndex: 1000,
            background: 'black url(img/loading.gif) no-repeat center'
        })
        .fadeIn(500,function(){
            $.get( obj.href+'&js',function(data){
            $('#stylesheet').attr('href','/media/css/' + data + '.css');

                cssDummy.check(function(){
                    $('#overlay').fadeOut(500,function(){
                        $(this).remove();
                    }); 
                });
            });
        });
}
var cssDummy = {
    init: function(){
        $('<div id="dummy-element" style="display:none" />').appendTo('body');
    },
    check: function(callback) {
        if ($('#dummy-element').width()==2) callback();
        else setTimeout(function(){cssDummy.check(callback)}, 200);
    }
}
cssDummy.init();

}

On clicking the link to change the stylesheet I get this error rturned via firebug,

An Error Was Encountered

The URI you submitted has disallowed characters.

the URL that is being sent is,

http://mywebsite/index.php/welcome/setBackground/green&js

this example is me clicking the green choice.

  • 写回答

2条回答 默认 最新

  • douqiao1887 2010-01-24 18:05
    关注

    try removing +'&js' part from:

    ...
    $.get( obj.href+'&js',function(data){
    ...
    

    in jQuery plugin.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器