douchuang4402 2013-01-14 15:50
浏览 45
已采纳

使用colorbox ajax通过提交发送数据

HTML

<div class="cus_input">
    <form id="category_form" method="GET" action="<?php echo base_url(); ?>welcome/find/" >
        <input type="text" id="category_input" name="q" placeholder=" Find Category"/>
        <a type="submit" class="ajax cboxElement" id="category_submit" src="<?php echo base_url() ?>img/board/icons/add.jpg" value="" />
    </form>
</div>

Controller

    function find()
{
        $this->pageload_model->load_page();
        $getquery = $this->input->get("q");
        $data['find'] = $this->find_model->get_find_view($getquery);
        $page['content'] = $this->load->view("template/findtemplate.php", $data);
        echo json_encode($page);
}

This controller correctly generates my desired results when you manually go to the URI. It was slightly modified in the attempt to use jquery ui dialog. However, i'd much rather use colorbox or fancybox at this point.

find model:

    public function get_find_view($q)
    {
        if (!$q) {
        $html = "Search disrupted: <a href='". base_url()."'>Go back to main page </a>";
        return $html;
        } else {
        $accountdata['found'] = $this->find_model->get_found_view($q);
        $accountdata['create_category'] = $this->find_model->get_create_category_view($q);
        return $this->load->view('find/find_view', $accountdata , TRUE);
        }
    }

the colobox ajax JS should be: $('ajax').colorbox()

I have the ajax class in 2 areas...a straight up link, which works with no problems, and the above mentioned submit button. What I am looking to do is send the input value to the find() controller, load the page, and open it via the colorbox window. I eventually would add a change to pushstate, so that the new URL / page can be crawled and shared.

I am having no luck. Thanks for the help! Will add any code you might need.

  • 写回答

1条回答 默认 最新

  • drgaeqdqiiyg14608 2013-01-14 16:41
    关注

    I haven't used colorbox before so I'm not 100% on this. I think what you need to do is serialize the data from your form and handle the ajax request yourself. So something like this:

    HTML:

    <div class="cus_input">
        <form id="category_form" method="GET" action="<?php echo base_url(); ?>welcome/find/" onsubmit="return category_form_submit();" >
        <input type="text" id="category_input" name="q" placeholder=" Find Category"/>
        <a type="submit" id="category_submit" src="<?php echo base_url() ?>img/board/icons/add.jpg" value=""/>
        </form>
    </div>
    

    JQUERY:

    function category_form_submit() {  
        $.get('/welcome/find?' + $('#category_form').serialize(), function(response){
            $.fn.colorbox({html:response});
            //here is where you could put your pushstate code
        });
        return false;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序