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