开发者

Load jQuery dialog from Controller/View?

开发者 https://www.devze.com 2023-03-25 06:59 出处:网络
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

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('adm开发者_运维百科in/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.
        }
    }


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!!!


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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消