Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit an <input type="file" /> using jQuery $.post

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.

like image 325
LoneWOLFs Avatar asked Feb 13 '26 10:02

LoneWOLFs


1 Answers

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

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

like image 123
Matías Fidemraizer Avatar answered Feb 15 '26 23:02

Matías Fidemraizer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!