发送数据通过提交使用颜色框阿贾克斯颜色、数据、框阿贾克斯

2023-09-10 20:57:15 作者:﹌再拽的網名終究被備注

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>

控制器

    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);
}

此控制器正确生成我想要的结果,当你手动去到URI。有人略加修改即可使用jQuery用户界面对话框中的尝试。但是,我宁愿使用颜色框和的fancybox在这一点上。

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.

查找型号:

    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);
        }
    }

在colobox AJAX JS应该是: $('阿贾克斯')颜色框()

我在2区的AJAX类的......一个直线上升的联系,这没有问题的作品,和上面提到的提交按钮。我所希望做的是输入值发送到查找()控制器,加载页面,并通过颜色框窗口中打开。最终我想补充一个改变pushstate,从而使新的URL /页,可以抓取和共享。

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.

我有没有运气。谢谢您的帮助!将添加任何code,你也许需要。

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

推荐答案

我没有用颜色框之前,所以我对这个不是100%。我想你需要做的是自己的序列从表单中的数据和处理Ajax请求。因此,像这样:

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:

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;
}