1

Is this possible? I'm thinking it should be as long as the server supports resume (HTTP RANGE).

5
  • 1
    The server doesn't know what you want unless you tell it to. Make your server understand that you only want a certain byte range for the response. Ajax is simply there to read the response and use it in-script. So, this isn't really a matter of Ajax. Unless you want to filter the whole response once retrieved. Commented Aug 22, 2015 at 22:48
  • @Jamen, yes, and I want to "tell it" using the HTTP RANGE command. How to do this is the question. Commented Aug 22, 2015 at 22:49
  • I think you just have to set the RANGE header with AJAX. Answer with code coming up! Commented Aug 22, 2015 at 22:50
  • What is the use case for this? Commented Aug 22, 2015 at 22:52
  • @charlietfl Read a line from a large fixed-width file on a CDN. Commented Aug 22, 2015 at 23:08

1 Answer 1

3

Use XMLHttpRequest.prototype.setRequestHeader() to set the RANGE request header:

//Our AJAX object:
var req = new XMLHttpRequest();
req.open([REQUEST METHOD], [REQUEST URI], true);
//Set the RANGE header here:
req.setRequestHeader("RANGE", "value-of-RANGE-header");
// [Here, set anything else you need before sending the request, like onstatechange]
//Now, send!
req.send();
Sign up to request clarification or add additional context in comments.

4 Comments

I get ERR_CONTENT_DECODING_FAILED in Chrome. Also, you have a capitalization error in XMLHttpRequest
Nm, works with proper Content-Type response from server, thanks!
Awesome! Glad I could help!
learn something new every day...didn't know this could be done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.