Can anyone explain why files cant be uploaded using AJAX?

前端 未结 4 713
北荒
北荒 2021-01-22 01:06

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).

Ca

相关标签:
4条回答
  • 2021-01-22 01:27

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

    0 讨论(0)
  • 2021-01-22 01:28

    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.

    0 讨论(0)
  • 2021-01-22 01:37

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

    0 讨论(0)
  • 2021-01-22 01:40

    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.

    0 讨论(0)
提交回复
热议问题