dry9192 2013-01-10 18:45
浏览 37
已采纳

在jquery ui模式中加载ajax数据(提交后)

I would like to pass data from a input form to my codeigniter controller, then return a view via JSON that will then be opened in a jquery ui dialog modal...phew!

It isn't working though. On submit, it refreshes the page, and no alerts work either (if I put it at the beginning of the findcat() function).

Here is my Javascript function:

function findcat(){
    var valinput = $('#category_form').val();
    $.ajax({
        type: "POST",
        async: true,
        url: 'http://rickymason.net/omnia/ajax/findcategory',
        dataType: 'json', 
        data: { valinput: valinput },
        success: function(content){
            $('#category_modal').html(content['content']);
            $('#category_modal').dialog({
                autoOpen: false,
                title: 'Hello',
                modal: true,
                height: 350,
                resizable: false 
            });
        return false;
        }
    });  
}

And my HTML:

<div class="cus_input">
    <form id="category_form" onsubmit="return findcat();">
        <input type="text" id="category_input" name="category_input" placeholder=" Find Category"/>
        <input type="image" id="category_submit" src="<?php echo base_url() ?>img/board/icons/add.jpg" id="homeSubmit" value="X"/>
    </form>
</div>

my controller is just a mockup to try and send some sort of content back:

    public function findcategory()
    {
        $page['content'] = 'hello-testing';
        return json_encode($page);
    }
  • 写回答

4条回答 默认 最新

  • douqiao1997 2013-01-10 18:55
    关注

    Assuming return false; is used to stop the form from submitting, its in the wrong place. It should be directly in findcat as you have it it is in the ajax success function.

    function findcat(){
        var valinput = $('#category_form').val();
        $.ajax({
            type: "POST",
            async: true,
            url: 'http://rickymason.net/omnia/ajax/findcategory',
            dataType: 'json', 
            data: { valinput: valinput },
            success: function(content){
                $('#category_modal').html(content['content']);
                $('#category_modal').dialog({
                    autoOpen: false,
                    title: 'Hello',
                    modal: true,
                    height: 350,
                    resizable: false 
                });
            }
        });  
        return false;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问