Submit an <input type=“file” /> using jQuery

2020-06-24 08:14发布

问题:

I have a <div/> tag which contains a file upload <input id="file" type="file"/> tag. I want to post the contents of the input tag to a php page using $.ajax() or $.post() but how do I grab the contents of the input tag having its type as "file"? so I can submit it using the jQuery ajax functions?

Note: My code doesn't have a <form/> tag yet. I am not sure if its mandatory to upload files. Also i've seen some workarounds using <iframe> I want to know if this can be done otherwise.

I don't want to use any plugins to do this.

回答1:

A byte stream can't be part of an asynchronous request.

In other words, you can't send data using AJAX approaches.



回答2:

you can't send file through $.post... you can use this link to uplaod file through ajax.. http://www.uploadify.com/demos/