How to open a partial view from controller as a Jquery Mobile dialog?

Load JQuery dialog from Controller/View?

  • 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 JQeury 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 follow 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. } }

  • Answer:

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

user464180 at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

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?

Evan

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

user798482

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.