2011-08-03 60 views
1

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

我想成功(或不)​​在相同的jQuery对话框(或打开一个新的)而不是调用/加载整个视图。

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

谢谢。

**编辑:添加代码如下+评论 - 谢谢! **

我INTIAL视图包含以下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. 
     } 
    } 
+0

我们可以看到一些代码吗?你做了一个体面的工作来解释这个问题,但如果我们看到你现在的代码,那么给你指点会更清楚和更容易。 – slandau

+0

添加上面的代码。谢谢! – user464180

回答

0

变量$对话框中的数据;函数showDialog(html,状态,请求){$ dialog.dialog('open'); $ dialog.html(HTML);返回false; (文件).ready(function(){$ dialog = $('')。dialog({autoOpen:false,modal:true,title:'导出对话框',按钮:{'好',':')。 function(){jQuery()。download('<%= submitURL%>',$ data,function(){jQuery('#wait')。hide(); $ dialog.dialog('close');}, ('#');},'Cancel':function(){jQuery(this).dialog('close');}}});

$('#popup')。click(function(){ jQuery.ajax({URL: '<%= submitURL%>',数据类型: '字符串',成功:的ShowDialog,数据: '数据',类型: '后'});});

couldnt format!!!

0

不确定你的问题,但也许你可以让你的控制器在iFrame中加载视图,然后把iFrame放到对话框中?

0

使用AJAX来提交,并在成功接收文本回:回调()方法来呈现对话框