0
我需要javascript中的sendAsBinary()
函数,但似乎Chrome本身已将其删除。在Mozilla的MDN(https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest),它们提供延伸了XMLHttpRequest原型的自定义函数:Chrome中的XML XMLHttpRequest.sendAsBinary()支持
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()
消息。
无法重现。按照您的指定,所有后续的新XMLHttpRequest对象都有一个'sendAsBinary'方法。铬30 – Brian