You can set headers on XML requests via setRequestHeader
, e.g. if xhr
is an XMLHttpRequest
instance:
xhr.setRequestHeader('HeaderName', 'HeaderValue');
I just tested it, and this gave me the first 56 characters of the file I requested:
var xhr = new XMLHttpRequest();
xhr.open("get", "thefile");
xhr.setRequestHeader("Range", "bytes=0-100");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
$("<p>").text("status = " + xhr.status + ", length = " + xhr.responseText.length + ", text = " + xhr.responseText).appendTo(document.body);
}
};
xhr.send();
Note that the status comes back as 206 (Partial Content), not 200.
Why 56 characters? Probably a bytes vs. characters thing in my test.