0

Possible Duplicate:
Is it possible to use Ajax to do file upload?

I'm trying to upload the image using jquery ajax.I used Jquery Load function. I checked from firebug all the input fields are submitted except the image field that is type=file.

 CakePhp Code
    echo $this->Form->input('Testimonial.photo', array('type'=>'file', 'label'=>'Upload Avator'));

 Jquery Function
    $('a[rel=save]').live('click',function(clickEvent) {
            clickEvent.preventDefault();
            var url = $(this).attr('href');
            $("#block").load(url, $("#form :input").serializeArray(),function(){
                }
            );
        });

How can i overcome this issue?

Community
  • 1
  • 1
Sujan
  • 81
  • 1
  • 11

2 Answers2

1

input type="file" elements cannot be transferred using regular jQuery Ajax. You should take a look at the new File API in combination with "XMLHttpRequest level 2" that (unfortunately) is not supported by all modern browsers yet.

Workaround: iframe or Flash solutions (search for "uploadify" for example).

devnull69
  • 16,402
  • 8
  • 50
  • 61
  • FYI, Uploadify can be difficult to implement if you have authentication in your site because sessions are not picked up by it and passed through by default. – BrettJ Nov 14 '12 at 15:07
0

You can have a look at jQuery form plugin.

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531