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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建