Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    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.

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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
    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
    Last edited by liorean; 11-13-2006 at 07:18 PM.
    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

  • #4
    New Coder
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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

  • #6
    New Coder
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Got it, thanks!
    Last edited by realtimethrill; 11-19-2006 at 03:50 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •