tags:

views:

86

answers:

4

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?

+7  A: 

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.

David Dorward
Can you give an example of what you mean David? (i.e. a snippet that demonstrates use of this 'extended AJAX' you mention, to load a file
Stick it to THE MAN
Submit a form to a hidden iframe.
David Dorward
+4  A: 

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

Victor Nicollet
A: 

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.

Darin Dimitrov
A: 

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

Longshanks