2011-08-03 83 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來提交,並在成功接收文本回:回調()方法來呈現對話框