开发者

Can anyone explain why files cant be uploaded using AJAX?

开发者 https://www.devze.com 2022-12-15 05:56 出处:网络
I have read many articles etc that attempt to explain why a file (e.g. attachment etc) cannot be uploaded via AJAX (atleast without some \'tricks\' behind the scene).

I have read many articles etc that attempt to explain why a file (e.g. attachment etc) cannot be uploaded via AJAX (atleast without some 'tricks' behind the scene).

Can anyone explain CLEARLY and SIMPLY, the technological reasons for this 'feature'开发者_运维知识库 of AJAX?


They can. It is XMLHttpRequest that can't be used to upload files. (But Ajax is more than XHR)

This is because, for security reasons, JavaScript can't read from the file system, so it can't get the file to hand to XHR.


For security reasons, modern browsers do not allow Javascript to access files on the viewer's computer.


File uploads are performed through a standard called multipart/form-data. Javascript has no way of reading the contents of files on the client computer.


Simply because javascript cannot access the file system...for obvious security reasons.

0

精彩评论

暂无评论...
验证码 换一张
取 消