Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery ajax image upload

Tags:

jquery

ajax

image

as the title describes i would like to create an image upload with ajax with jQuery. As far as I know right now, there is no image ajax uploading. Workarounds are iframes and flash. Since i don't like flash, i'm fine with the iframe hack, i hope. Like they do it here: http://tinyw.in/UNnp

I have an element. I want to make it possible, to double click on the element, then a file browser appears, you choose your image, it gets uploaded and the image's src you just clicked get's changed to the new uploaded image's path. Doesn't really sound that hard.

Actually, that's what the link i posted above does. I don't know what it does in detail, how it handels everything, since there is no documentation.

So, can me anyone explain what that plugin does in the backend, so i understand it. I don't know what i should do with the php.php file, what i should pass as an action of the form.

Thanks

like image 623
handy Avatar asked Nov 22 '11 16:11

handy


People also ask

Can we upload image using AJAX?

jQuery AJAX image upload requires core jQuery features and nothing fancy is used. For AJAX image upload, enctype='multipart/form-data' is not required as we are not submitting via form post. We are using AJAX data transfer and multipart form data is not required for the image upload.

How to send image file in AJAX jQuery to controller?

button('loading'); var data = $('#first-form'). serialize(); var formData = new FormData(); formdata. append("img", fileImage ); $. post("/Contractor/SendConfirmCode", data, function(result) { } else { } }, "json");


1 Answers

http://jquery.malsup.com/form/ this plugin is very nice. Just create a form, init the plugin with it and you are done. Just handle the uploaded files within PHP's $_FILES[]

like image 191
xotix Avatar answered Oct 14 '22 17:10

xotix