Skip to content

Instantly share code, notes, and snippets.

@RushOnline
Created May 2, 2013 23:00
Show Gist options
  • Save RushOnline/5506113 to your computer and use it in GitHub Desktop.
Save RushOnline/5506113 to your computer and use it in GitHub Desktop.
To get right binary response we must use overrideMimeType method of XHR in beforeSend filter method of jQuery ajax call.
$.ajax({
type: "POST",
url: href,
beforeSend: function (xhr) {
xhr.overrideMimeType("text/plain; charset=x-user-defined");
},
success: function(response) {
var binary = Array.prototype.map.call(response, function(c) { return c.charCodeAt(0) & 0xFF; });
console.debug('ajax done: ', binary);
},
error: function(result) {
console.debug('ajax failed: ', result);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment