【发布时间】: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