Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2006, 12:44 AM   PM User | #1
realtimethrill
New Coder

 
Join Date: Feb 2006
Posts: 60
Thanks: 2
Thanked 0 Times in 0 Posts
realtimethrill is an unknown quantity at this point
AJAX -at what point transfer happens

Hi
At this w3schools example, 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
realtimethrill is offline   Reply With Quote
Old 11-13-2006, 08:57 AM   PM User | #2
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
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.
Beagle is offline   Reply With Quote
Old 11-13-2006, 07:13 PM   PM User | #3
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
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.


Note:
The example doesn't actually make a HEAD request
Quote:
Code:
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
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...


Edit: Yes, you should send them an angry mail... or at least some type of feedback
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

Last edited by liorean; 11-13-2006 at 07:18 PM..
liorean is offline   Reply With Quote
Old 11-18-2006, 01:28 PM   PM User | #4
realtimethrill
New Coder

 
Join Date: Feb 2006
Posts: 60
Thanks: 2
Thanked 0 Times in 0 Posts
realtimethrill is an unknown quantity at this point
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
realtimethrill is offline   Reply With Quote
Old 11-18-2006, 09:53 PM   PM User | #5
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
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.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 11-19-2006, 03:15 PM   PM User | #6
realtimethrill
New Coder

 
Join Date: Feb 2006
Posts: 60
Thanks: 2
Thanked 0 Times in 0 Posts
realtimethrill is an unknown quantity at this point
Got it, thanks!

Last edited by realtimethrill; 11-19-2006 at 03:50 PM..
realtimethrill is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:56 PM.


Advertisement
Log in to turn off these ads.