Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File Upload via AJAX within JQuery

I am new to JQuery AJAX . I want to implement a file upload using a jquery. Will it be possible to make a fileupload with JQuery,AJAX and send it to Servlet which can use apache file commons to upload the file. Can anyone please advice me how to proceed further?

Thanks, Deepthi.

like image 460
user200290 Avatar asked Nov 06 '09 08:11

user200290


People also ask

Can we upload file using AJAX?

File upload is not possible through AJAX. You can upload file, without refreshing page by using IFrame .

How files are handled in AJAX?

A component must exist on the server to handle the file upload and save the resource locally; The server must send a response to the browser indicating the JavaScript file upload was successful; and. The client's browser must provide an Ajax-based response indicating the file uploaded successfully.


2 Answers

Ajax in the traditional sense is XMLHttpRequest, which does not allow you encode and send local files to a server.

The common ways of doing uploading through "ajax" means, is to either use a Flash swf to handle the uploading on the same page, or to use a form that has a target of an invisible 1x1 iframe. You have some Javascript show a uploading spinner or whichever. After the file is uploaded, make the server return some Javascript to the iframe like

<script type="text/javascript">
top.MyProject.doneUploading();
</script>

top will allow you to call Javascript in the regular page. In order for that to work though, you must make sure the iframe has submitted to the same domain that the top document is located at.

like image 122
seanmonstar Avatar answered Sep 19 '22 09:09

seanmonstar


I had several problems using Uploadify so I turned to ajax upload

like image 34
pedro Avatar answered Sep 18 '22 09:09

pedro