Welcome Guest, Not a member yet? Register   Sign In
AJAX Response
#10

[eluser]NateL[/eluser]
I guess it would make more sense if I told you I'm using jQuery and a plugin called Ajax Upload (first example)

My code: upload_view.php
Code:
< script type= "text/javascript">/*<![CDATA[*/
$(document).ready(function(){

    /* example 1 */
    var button = $('#button1'), interval;
    new Ajax_upload(button,{
        action: '/admin/upload/do_upload',
        name: 'userfile',
        onSubmit : function(file, ext){
            // change button text, when user selects file            
            button.text('Uploading');
            
            // If you want to allow uploading only 1 file at time,
            // you can disable upload button
            this.disable();
        
            
            // Uploding -> Uploading. -> Uploading...
            interval = window.setInterval(function(){
                var text = button.text();
                if (text.length < 13){
                    button.text(text + '.');                    
                } else {
                    button.text('Please Wait');                
                }
            }, 200);
        },
        onComplete: function(file, response){
            //alert(response);
            button.text('Upload');
                        
            window.clearInterval(interval);
                        
            // enable upload button
            this.enable();

            console.log(response);
            
            // add file to the list
/*             $('<li></li>').appendTo('#example1 .files').text(file);                         */
        }
    });
});/*]]>*/[removed]

The action sends it to my upload controller, which process it:
upload.php
Code:
function do_upload()
    {
        // Image configuration
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['overwrite'] = FALSE;
        $config['max_size'] = 2048;
        
        $this->load->library('upload', $config);
        
    
        if(!$this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_form', $error);
        }
        else
        {
            
        
            $image = $this->upload->data();
            $data['image'] = "./uploads/".$image['file_name'];
            
            $config['image_library'] = 'gd2';
            $config['source_image'] = $data['image'];
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            //$config['master_dim'] = width;
            $config['width'] = 75;
            $config['new_image'] = "./uploads/".$image['file_name'];
            
            $this->load->library('image_lib', $config);
            
            $this->image_lib->resize();
            
            $data = array('upload_data' => $this->upload->data());
                        
            $this->load->view('upload_success', $data);
            

        }
    }

So - in my upload controller, instead of
$this->load->view('upload_success', $data);

I just want to return the file_name to the script that sent it so I can display the image below the "Upload" button.

Hope this helps to clear somethings up Smile

Thanks for the assistance!


Messages In This Thread
AJAX Response - by El Forum - 02-21-2009, 09:12 PM
AJAX Response - by El Forum - 02-21-2009, 10:06 PM
AJAX Response - by El Forum - 02-21-2009, 10:25 PM
AJAX Response - by El Forum - 02-21-2009, 10:59 PM
AJAX Response - by El Forum - 02-23-2009, 09:50 PM
AJAX Response - by El Forum - 02-24-2009, 05:51 AM
AJAX Response - by El Forum - 02-24-2009, 09:10 AM
AJAX Response - by El Forum - 02-24-2009, 12:22 PM
AJAX Response - by El Forum - 02-24-2009, 12:46 PM
AJAX Response - by El Forum - 02-24-2009, 12:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB