【发布时间】:2013-11-03 21:52:23
【问题描述】:
我需要 javascript 中的 sendAsBinary() 函数,但 Chrome 似乎已将其删除。在 Mozilla MDN (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) 上,它们提供了一个扩展 XMLHttpRequest 原型的自定义函数:
if(!XMLHttpRequest.prototype.sendAsBinary) {
XMLHttpRequest.prototype.sendAsBinary = function(sData) {
console.log("calling sendAsBinary() method...");
var nBytes = sData.length, ui8Data = new Uint8Array(nBytes);
for(var nIdx = 0; nIdx < nBytes; nIdx++) {
ui8Data[nIdx] = sData.charCodeAt(nIdx) & 0xff;
}
this.send(ui8Data);
};
}
但是,即使我实现了上述内容,我仍然得到:
Uncaught TypeError: Object #<XMLHttpRequest> has no method 'sendAsBinary'
在Chrome 30.0.1599.101。我也从来没有看到我的console.log() 消息。
【问题讨论】:
-
无法复制。所有后续的
new XMLHttpRequest对象都有一个sendAsBinary方法,正如您指定的那样。铬 30
标签: javascript ajax xmlhttprequest jqxhr