how to find the file inside input element html using jquery

i was trying to upload a file via $.ajax call using jQuery.. and formData

in order to append the file to the formData i did the following:

var fd = new formData();
fd.append($('#myFileInput));

that failed

then i tried :

var fd = new formData();
fd.append($('#myFileInput).files[0]);

and again it failed then i tried:

var fd = new formData();
fd.append($('#myFileInput')[0].files[0]);

and that really worked and i could send my file to the server..

my question is:

why should I use the [0] next to the jquery object representing my file input element.. ?? notice that i didn't use the "multiple" attribute for the file input

Answers


$('selector') returns a jQuery object, and "files" attribute belongs to the DOM object, thus you will need to retrieve the DOM object via $('selector')[0] or $('selector').get(0).


Need Your Help

WinForm chart control: Change size of chart when saving it to a file

c# winforms size save charts

is there a way to change size of chart when using method Chart.SaveImage() from the source code?

How is the code memory managed?

c++ c operating-system

When talking about a process' memory, I heard about things like code memory and data memory.