Modern Web Guidance is now stable! Upgrade your coding agents with expert-vetted web development best practices.
Read the announcement.
Arrived! xhr.send(ArrayBufferViews)
Stay organized with collections
Save and categorize content based on your preferences.
And here you thought we were done improving XHR!
For a while now XHR2's overloaded send() method has supported sending a ArrayBuffer (a raw byte array).
Chrome 22 (current Canary) deprecates this feature by replacing it with sending ArrayBufferViews instead. JS Typed Arrays are just special ArrayBufferViews, so all this really means is that you can now send a typed array directly across the wire without touching its underlying buffer. This change is in match step with the recent updates to the XMLHttpRequest2 spec.
So for example, instead of sending an ArrayBuffer:
var xhr = new XMLHttpRequest();
xhr.open('POST', '/server', true);
xhr.onload = function(e) { ... };
var uInt8Array = new Uint8Array([1, 2, 3]);
xhr.send(uInt8Array.buffer);
Just send the typed array itself:
xhr.send(uInt8Array);
Eventually, sending ArrayBuffers will be removed, but for the time being you'll get console warnings when trying to send a buffer.
As always, you can keep up with these types of changes by following chromestatus.com.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2012-07-15 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2012-07-15 UTC."],[],[]]