从控制器/视图加载 jQuery 对话框?

发布于 2024-11-27 22:23:11 字数 2103 浏览 2 评论 0原文

我正在使用 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.
        }
    }

I'm using jQuery dialog to load a view, which is used to upload files to my application. Upon browsing to the file and clicking submit, a controller is called, which processes the file and passes it to my model for insertion. The model then returns back to the controller, success (or not) and loads a new view for success (or not).

I would like to have the success (or not) view render inside the same jQuery dialog (or open a new one) instead of calling/loading an entire view.

Would I call/load (somehow) the jQuery dialog from within my controller? Or would I have my controller call the new view, and once it loads, have it render the dialog, basically rendering itself in the dialog? Hope this makes sense.

Thanks.

**EDITED: ADDED CODE BELOW + COMMENTS - Thanks! **

My intial view contains the following jQuery function, which is called when a user clicks on an anchor ("upload file"):

$(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);     
});

The function called by the controller:

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.
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

软糯酥胸 2024-12-04 22:23:11

var $dialog;函数 showDialog(html, 状态, 请求) { $dialog.dialog('open'); $dialog.html(html);返回假; }

$(document).ready(function() { $dialog = $('').dialog({ autoOpen: false, modal : true, title : '导出对话框', 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' }) });

无法格式化!!!

var $dialog; function showDialog(html, status,request) { $dialog.dialog('open'); $dialog.html(html); return 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'); }, 'Cancel': function() { jQuery(this).dialog('close'); } } });

$('#popup').click(function() { jQuery.ajax( { url : '<%=submitURL%>', dataType : 'String', success : showDialog, data : 'data', type : 'post' }); });

couldnt format!!!

溺ぐ爱和你が 2024-12-04 22:23:11

不确定您到底要问什么,但也许您可以让控制器在 iFrame 中加载视图,然后将 iFrame 放入对话框中?

not sure exactly what your asking but but maybe you could have your controller load the view in an iFrame, and then put the iFrame in your dialog?

躲猫猫 2024-12-04 22:23:11

使用 ajax 提交并成功接收文本:callback() 方法在对话框内呈现数据

use ajax to submit and receive text back in success : callback() method to render data inside the dialog

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文