我使用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.
}
}
我们可以看到一些代码吗?你做了一个体面的工作来解释这个问题,但如果我们看到你现在的代码,那么给你指点会更清楚和更容易。 – slandau
添加上面的代码。谢谢! – user464180