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 学校优化算法sbo和蚁群算法怎么结合
  • ¥20 Apache poi使用问题
  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素
  • ¥15 stc12c5a60s2、QMC5883L、LCD1602组合测量磁场所需程序
  • ¥20 Win11测试yolov4,“找不到nvcuda.dll”怎么办?
  • ¥15 simulink绘制bode图
  • ¥15 php_network_getaddresses: getaddrinfo failed: Name or service not known
  • ¥15 用msg发消息出现的问题