【问题标题】:Load jQuery dialog from Controller/View?从控制器/视图加载 jQuery 对话框?
【发布时间】:2011-10-19 11:54:23
【问题描述】:

我正在使用 jQuery 对话框加载视图,该视图用于将文件上传到我的应用程序。浏览到文件并单击提交后,将调用一个控制器,该控制器处理文件并将其传递给我的模型以进行插入。然后模型返回到控制器,成功(或不成功)并为成功(或不成功)加载一个新视图。

我希望成功(或不成功)视图在同一个 jQuery 对话框中呈现(或打开一个新对话框),而不是调用/加载整个视图。

我会从我的控制器中调用/加载(以某种方式)jQuery 对话框吗?或者我会让我的控制器调用新视图,一旦它加载,让它呈现对话框,基本上在对话框中呈现自己?希望这是有道理的。

谢谢。

**已编辑:在下方添加代码 + 评论 - 谢谢! **

我的初始视图包含以下 jQuery 函数,当用户单击锚点(“上传文件”)时会调用该函数:

$(document).ready(function(){
 function uploadImage(event) {
          id = $(this).data('id'); //id is an URL such as ('upload_form'/do_upload/5) it calls my controller (uploadimage), and passes a value (5) to a function (doupload)

          $("#dialog").load(id).dialog(); //loads the URL    
         return false;
    }

$('.imageBtn').live('click',uploadImage);     
});

控制器调用的函数:

function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '0';
        $config['max_width']  = '212';
        $config['max_height']  = '118';

        $this->load->library('upload', $config);    
        if ( ! $this->upload->do_upload())
        {
            $data['id'] = $this->input->post( 'iEventID', true );    
                        $data['error'] = $this->upload->display_errors();
            $this->load->view('admin/upload_form', $data); // If an error is found during file/img upload, then the code reloads the view that was previously loaded into my dialogue. This is where I need the same view to reload in the dialog and present the error message. This currently loads the view in its entirety in a browser window.
        }
        else
        {
            $upload_data = $this->upload->data(); 
            $filename = $upload_data['file_name'];    
            $this->event_model->addEventImage($filename);
            $this->load->view('admin/upload_success');  // If all is well, instead of loading the view in its entirety, I want to load the success into the dialog previously popped.
        }
    }

【问题讨论】:

  • 我们能看一些代码吗?您在解释问题方面做得不错,但如果我们看到您当前的代码,给您指点会更清晰、更容易。

标签: jquery dialog controller render


【解决方案1】:

var $对话框;功能 showDialog(html, status,request) { $dialog.dialog('open'); $dialog.html(html);返回假; }

$(document).ready(function() { $dialog = $('').dialog({ autoOpen: false, modal : true, title : 'Export Dialog', 按钮: { 'Ok': function( ) { jQuery().download( '', $data, function(){ jQuery('#wait').hide(); $dialog.dialog('close'); }, 'post '); }, '取消': function() { jQuery(this).dialog('close'); } } });

$('#popup').click(function() { jQuery.ajax( { url : '', dataType : 'String', 成功 : showDialog, data : 'data', 类型: '发布' }); });

couldnt format!!!

【讨论】:

    【解决方案2】:

    使用 ajax 成功提交和接收文本:callback() 方法在对话框内呈现数据

    【讨论】:

      【解决方案3】:

      不确定您的要求,但也许您可以让您的控制器将视图加载到 iFrame 中,然后将 iFrame 放入您的对话框中?

      【讨论】:

        最近更新 更多