So the problem is that you are not
really able to do that via classical
ajax requests.
In just normal html, you would generally have a <form method=‘post’ action=‘/api/path’>,
which would either refresh the whole page, or you could target it to an iframe.
The reasoning is that you aren’t actually passing the file as text into the browser window, but rather instructing the browser to read the data value from this file when it does the submission process. It doesn’t touch the javascript.
You can however use a sort of alternate api called FormData
This seems to be a file upload directive (from a quick glance only),
that implements this alternate api and a flash polyfill of some sort,
so that the data can actually go into your client side js for it
to work
This is another useful issue that explains a possibility. (note, it’s using FormData)