View Full Version : AJAX -at what point transfer happens

11-13-2006, 01:44 AM
At this w3schools example (http://www.w3schools.com/xml/tryit.asp?filename=try_xmlhttprequest_js2), they say that the method getAllResponseHeaders() will download the header of a file, not the file itself.

This seems wrong, as this method is called on the XMLHttpRequest object only when its readyState property is at 4 -which I assume means the file has already downloaded anyway?

Otherwise, does the transfer of the file actually occur only at the point of using things like xmlhttp.responseText, xmlhttp.responseXML or xmlhttp.getAllResponseHeaders() -that is, after the readyState property is detected as 4 ("complete")?

May sound pedantic, but seems like this could be important for very large files.

I'm wondering if I need to write them an angry email:)
Thanks for any help

11-13-2006, 09:57 AM
In ready state 4 the entire response has been consumed. All access to it after readystate 4 is reached doesn't do anything on the network, the data is already resident in memory.

11-13-2006, 08:13 PM
You're reading that a bit wrong - there's nothing about the XMLHttpRequest.prototype.getAllResponseHeaders method that has anything to do with whether the request will retrieve the entire file or not. And the example doesn't state that, either.

What the example does state is correct however: To request only the headers of a resource you can use the HEAD request type instead of GET or POST. The request type has nothing to do with the use of XMLHttpRequest.prototype.getAllResponseHeaders, the method will retrieve the response headers for ANY type of requests after the request has already been made.

The example doesn't actually make a HEAD request

As you see, the example is making a GET request and not a HEAD request. So the statement about HEAD requests doesn't have much to do with the actual example script. I take it that the authors haven't quite understood what they are trying to explain...

Yes, you should send them an angry mail... or at least some type of feedback

11-18-2006, 02:28 PM
That's great guys, thank you.

I tried running the kind of script they must have meant, and made a HEAD request. But I can't seem to read the response. Having made a HEAD rather GET/POST request, the responseText property of the XMLHttpRequest object is empty.

Any thoughts appreciated

11-18-2006, 10:53 PM
That's the meaning of HEAD requests: They only returns the headers, not the content. The GET/POST requests on the other hand always returns headers plus full content. If you want to read the content and possibly also the headers, you should use GET/POST. If you want to read the headers without having to download the contents, use a HEAD request.

11-19-2006, 04:15 PM
Got it, thanks!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum