javascript tutorial - [Solved-5 Solutions] jQuery Ajax File Upload - javascript - java script - javascript array
Problem:
Can we use the following jQuery code to perform file upload using post method of an Ajax request ?
If it is possible, do we need to fill "data" part? Is it the correct way ? We only post the file to the server side. We have been Googling around, but what we found was a plugin while in my plan we do not want to use it. At least for the moment.
Solution 1:
file upload is not possible through ajax. We can upload file, without refreshing page by using IFrame. UPDATE: With XHR2, File upload through AJAX is supported. E.g. through FormData object, but unfortunately it is not supported by all/old browsers. FormData support starts from following desktop browsers versions. IE 10+, Firefox 4.0+, Chrome 7+, Safarwe 5+, Opera 12+
Solution 2:
An AJAX upload is indeed possible with XMLHttpRequest(). No iframes necessary. Upload progress can be shown.
Solution 3:
- Use a hidden iframe and set our form's target to that iframe's name. This way, when the form is submitted, only the iframe will be refreshed.
- Have an event handler registered for the iframe's load event to parse the response.
Solution 4:
In case we want to do it like that: