我正在使用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.
}
}
答案 0 :(得分:0)
不确定您的要求但是也许您可以让控制器在iFrame中加载视图,然后将iFrame放入对话框中?
答案 1 :(得分:0)
使用ajax成功提交和接收文本:callback()方法在对话框中呈现数据
答案 2 :(得分:0)
var $ dialog; function showDialog(html,status,request){$ dialog.dialog('open'); $ dialog.html(HTML);返回false; }
$(document).ready(function(){$ dialog = $('')。dialog({autoOpen:false,modal:true,title:'Export Dialog',buttons:{'Ok':function( ){jQuery()。download('<%= submitURL%>',$ data,function(){jQuery('#wait')。hide(); $ dialog.dialog('close');}, 'post');},'取消':function(){jQuery(this).dialog('close');}}});
$('#popup')。click(function(){jQuery.ajax({url:'<%= submitURL%>',dataType:'String',success:showDialog,data:'data' ,输入:'post'});});
couldnt format!!!