Side navigation
#9992 closed feature (patchwelcome)
Opened August 06, 2011 11:39AM UTC
Closed August 18, 2011 04:44PM UTC
$.get binary
Reported by: | sfornengo@gmail.com | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | ajax | Version: | 1.6.2 |
Keywords: | Cc: | jaubourg | |
Blocked by: | Blocking: |
Description
it would be nice if we could get "arraybuffer" or "blob" response type from ajax request.
it seems direct "blob" response is not yet supported by all browser (chrome don't) but we can easily build it from arraybuffer:
var xhr=new XMLHttpRequest(); xhr.open("GET",url,true); xhr.responseType="arraybuffer"; xhr.onload=function(){ if (this.status==200){ var bb=new BlobBuilder(); bb.append(this.response); var blob=bb.getBlob()); //... } }; xhr.send();
Attachments (0)
Change History (3)
Changed August 07, 2011 01:25PM UTC by comment:1
cc: | → jaubourg |
---|---|
component: | unfiled → ajax |
priority: | undecided → low |
Changed August 07, 2011 02:45PM UTC by comment:2
description: | it would be nice if we could get "arraybuffer" or "blob" response type from ajax request.[[BR]] \ it seems direct "blob" response is not yet supported by all browser (chrome don't) but we can easily build it from arraybuffer:[[BR]] \ \ var xhr=new XMLHttpRequest();[[BR]] \ xhr.open("GET",url,true);[[BR]] \ xhr.responseType="arraybuffer";[[BR]] \ xhr.onload=function(){[[BR]] \ if (this.status==200){[[BR]] \ var bb=new BlobBuilder();[[BR]] \ bb.append(this.response);[[BR]] \ var blob=bb.getBlob());[[BR]] \ ...[[BR]] \ }[[BR]] \ };[[BR]] \ xhr.send(); \ → it would be nice if we could get "arraybuffer" or "blob" response type from ajax request.[[BR]] \ it seems direct "blob" response is not yet supported by all browser (chrome don't) but we can easily build it from arraybuffer: \ {{{#!js \ var xhr=new XMLHttpRequest(); \ xhr.open("GET",url,true); \ xhr.responseType="arraybuffer"; \ xhr.onload=function(){ \ if (this.status==200){ \ var bb=new BlobBuilder(); \ bb.append(this.response); \ var blob=bb.getBlob()); \ //... \ } \ }; \ xhr.send(); \ }}} |
---|
Maybe it could be implemented using a "text bin" converter. You'd need a prefilter for bin requests to add responseType: "arraybuffey" into options.xhrFields though. And that's provided xhr.responseText === xhr.response which I'm really not sure about.
So, this may require changes in the xhr transport... but I'm unsure if this is already "standard" enough (ie. not requiring insane jumping through hoops).
Changed August 18, 2011 04:44PM UTC by comment:3
resolution: | → patchwelcome |
---|---|
status: | new → closed |
Sounds like this should start life as a converter, outside core. If it's popular we can incorporate it.
I think this is best implemented with a converter, but I'll defer to jaubourg.