【问题标题】:ajax form in codeignitter - sending generated formcodeigniter 中的 ajax 表单 - 发送生成的表单
【发布时间】:2018-09-20 18:41:10
【问题描述】:

我想打开一个模式并从控制器获取内容(公式)。

此步骤工作正常。

现在我在模态中有了公式。我如何提交这些公式并使用相同的控制器功能对其进行处理?

目前我以这种方式进行 Ajax-Call

$('.modaldisconnect').click(function(){
                var modid = $(this).attr('modid');
                $.ajax({
                    url: "<?php echo base_url() ?>admin/module/disconnect_form",
                    method: "POST",
                    data: {modid:modid},
                    // Callback function that is executed after data is successfully sent and recieved
                    success: function(data){
                     // Print the fetched data of the selected phone in the section called #phone_result 
                     // within the Bootstrap modal
                        $('.modal-ajax-content').html(data);
                        // Display the Bootstrap modal
                        $('#disconnect_modal').modal('show');
                    },
                        error: function(error){
                        // Show error message
                        alert('error');
                            }
             });
            });

这是通过上面的调用从控制器生成的表单

echo'   <div class="modal-body">
                <div id="modul_disc_infos">
                    <span class="module-headlines-title">'._l("modul_name").': <span id="disc_modulname">'._l('module_'.$result->folder.'_titel').'</span></span>
                    <span class="module-headlines-subtitle">'._l("modul_disconnect_deadline").': <span id="disc_enddate">'.$enddate.'</span></span>                 
                </div>
                <div id="modul_disc_check">
                    <div class="alert alert-danger" role="alert">'._l("modul_disconnect_disclaimer").'</div>
                    <hr>
                    <input type="checkbox" name="check_disclaimer" value="1"> '._l("modul_disconnect_disclaimer_check").'   
                    <input type="hidden" name="modid" value="'.$this->input->post('modid').'">
                    <input type="hidden" name="formstep" value="1">                 
                    '.$errormsg.'               
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">'._l('close').'</button>
                <button type="button" class="btn btn-danger" id="submit_disconnect" >'._l('modul_disconnect_now').'</button>
            </div>';

顺便说一句 - 有没有更好的方法来解析公式的值,而不是像我的代码“var modid = $(this).attr('modid');”中的一样?

【问题讨论】:

    标签: ajax codeigniter


    【解决方案1】:

    我已经通过这种方式解决了我执行 2 个不同的 ajax 调用的问题,首先是单击或提交表单或特定按钮。一调用生成表单,一调用处理表单。对我来说,它很有效,并且可以灵活地将相同的功能用于不同的工作。

    //Formular for disconnection
                $('.modaldisconnect').click(function(){
                    var modid = $(this).attr('modid');
                    $('#ajax_modal_title').html('<?php echo _l('modul_disconnect'); ?>');
    
                    $.ajax({
                        url: "<?php echo base_url() ?>admin/module/disconnect_form",
                        method: "POST",
                        data: {modid:modid},
                        // Callback function that is executed after data is successfully sent and recieved
                        success: function(data){
                         // Print the fetched data of the selected phone in the section called #phone_result 
                         // within the Bootstrap modal
                            $('.modal-ajax-content').html(data);
                            // Display the Bootstrap modal
                            $('#ajax_modal').modal('show');
                        },
                            error: function(error){
                            // Show error message
                            alert('error');
                                }
                 });
                });
    
          //Handle the disconnection  
            $("#ajax_form").on("submit", function (event) {
            event.preventDefault();
            subform=$('input[name="subform"]').val();
            $.ajax({
                url: "<?php echo base_url() ?>admin/module/"+subform+"_form",
                type: "POST",
                data: $('#ajax_form').serialize(), 
                success: function(result){
                    $('.modal-ajax-content').html(result);
                },
                            error: function(error){
                            // Show error message
                            alert('error');
                                }
            });
        });        
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多