If you need to include headers in your XML requests, you can use the setRequestHeader
method. For example, if you have an XMLHttpRequest instance called xhr
:
xhr.setRequestHeader('HeaderName', 'HeaderValue');
In a recent test I conducted, I was able to retrieve the first 56 characters of a specific file by using the following code:
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();
It's worth noting that the response status returned as 206 (Partial Content) instead of the standard 200.
The reason for only retrieving 56 characters could be due to differences between bytes and characters in my testing environment.