Skip to content

Instantly share code, notes, and snippets.

@HerrPi
Last active December 31, 2015 20:09
Show Gist options
  • Save HerrPi/8038159 to your computer and use it in GitHub Desktop.
Save HerrPi/8038159 to your computer and use it in GitHub Desktop.
Load the first 5 bytes of a file with a jQuery ajax request. Beforehand, check whether the Range header is supported.
$(document).ready(function () {
$.ajax({
success: function (data, status, jqxhr) {
if (jqxhr.getResponseHeader("Accept-Ranges") == "bytes") {
$.ajax({
headers: {
"Range": "bytes=0-4"
},
success: function (data) {
$("pre").text(data);
},
type: "GET",
url: "some_local_file"
});
} else {
alert("Range header not supported.");
}
},
type: "HEAD",
url: "some_local_file"
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment