I am relatively new to jQuery and Ajax functions, but have been working with Ajax forms in the last few days. When I tried to download images, I had a problem downloading files. Although I was looking for resources, I could not find anything useful, because they seem overly complex with meaningless additions or have no explanation, which does not help me learn further.
I wrote this code to handle image loading in Ajax:
$(function() { $('.input_photo').on("change",function() { var formData = new FormData($('form.upload-form')); $.ajax({ url: "upload.php", type: "POST", data: formData, success: function (msg) { alert(msg) } }); }); });
This sends the request to the upload.php file, however the data is not sent, basically my form is literally like this:
<form class="upload-form"> <input type="file" name="input_photo" class="input_photo" /> </form>
No data is passed in the headers at all, and I assume that I am accessing it through PHP with an array of $_POST['data'] or $_FILES ? Someone with better knowledge, please help explain this, it would be great to understand this further. Thanks.
Danny source share