Re: Using XmlHttpRequest to upload [binary] data
Vladimir Kelman <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Organization | Another Netscape Collabra Server User |
| Message-ID | <[email protected]> |
Emmanuil Batsis (Manos) wrote: >> I'm trying to write [JavaScript] code to upload [binary] files from >> user's machine to a server (PHP page) using XmlHttpRequest object. > > You'll need to encode the binary file in base64 (possible with > javascript, google for it) and wrap it in markup. Excuse me, what do you mean by "wrapping it into markup"? But any way, the very first thing is how to read a file (I understand that reading of local files was prohibited in JavaScript by security purposes). I'm starting to investigate Mozilla XML extras right now. (Crazy guys at MS are apparently rearranging something, so most of the MSDN links are broken and I cannot even find MS XmlHttpRequest object reference for now.) >> The very first question is how to attach a file to XmlHttpRequest? As >> I understand I need to create something called a "stream" to do it. Is >> it possible to do it in Mozilla and IE using JavaScript and possible XML? > > Yes, google for mozilola XML extras and microsofts implementation to > find related docs. > > I dont see why you dont want to use plain HTML forms for this though > asynchonous operation being the only pro; but easily emulated by > wrapping the form in an iframe. I'm using XmlHttpRequest to post data onto server without page reloading in several projects now. I wrote kind of generic routine and found it to be very convenient tool. The main advantage over regular form.post(), IMHO, is that browser doesn't reload a page. So, for example, I don't need to save all the values into Session variables and then redisplay them in a case of error. Also this way browser doesn't need to redisplay the whole HTML page so, I believe, there is less network traffic too. I feel it is a better "Inner Browsing Paradigm" (http://devedge.netscape.com/viewsource/2003/inner-browsing/) than a regular form.post(). It looks more like desktop or client/server application. Unfortunately, I cannot block Forward and Back buttons in Mozilla (I understand it is a security feature, but that blocking can be done in IE http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onbeforeunload.asp.) Yes, I can emulate XmlHttpRequest file uploading with iframes. But it looks like an artificial trick to overcome a major paradigm shortage, doesn't it? And also, I believe, using form.post will create an entry in browser's History which I'm trying to avoid.