var addEvent = function (obj, evname, evhandler) { if - TopicsExpress



          

var addEvent = function (obj, evname, evhandler) { if (obj.addEventListener) { obj.addEventListener(evname, evhandler , false); } else { obj.attachEvent(on+evname, evhandler ); } }; /* For IE9 we must use this magic/hack that injects VBScript in the page. This is the only way to get access to the raw bytes in a binary response. Otherwise, the bytes 128-159 are mangled. */ var isIE = (typeof (window.ActiveXObject) != undefined); if(isIE) { var IEBinaryToArray_ByteStr_Script = \r\n+ \r\n+ Function IEBinaryToArray_ByteStr(Binary)\r\n+ IEBinaryToArray_ByteStr = CStr(Binary)\r\n+ End Function\r\n+ Function IEBinaryToArray_ByteStr_Last(Binary)\r\n+ Dim lastIndex\r\n+ lastIndex = LenB(Binary)\r\n+ if lastIndex mod 2 Then\r\n+ IEBinaryToArray_ByteStr_Last = Chr( AscB( MidB( Binary, lastIndex, 1 ) ) )\r\n+ Else\r\n+ IEBinaryToArray_ByteStr_Last = ++\r\n+ End If\r\n+ End Function\r\n+ \r\n; document.write(IEBinaryToArray_ByteStr_Script); /* The VB code below will return one char for every 2 chars in the string. We construct a mapping table to replace every such composed character with the two characters it encodes */ var ByteMapping = {}; for ( var i = 0; i < 256; i++ ) { for ( var j = 0; j < 256; j++ ) { ByteMapping[ String.fromCharCode( i + j * 256 ) ] = String.fromCharCode(i) + String.fromCharCode(j); } } function GetIEByteArray_ByteStr(IEByteArray) { var rawBytes = IEBinaryToArray_ByteStr(IEByteArray); var lastChr = IEBinaryToArray_ByteStr_Last(IEByteArray); return rawBytes.replace(/[\s\S]/g, function( match ) { return ByteMapping[match]; }) + lastChr; } /* IE9 also has another problem in postMessage: it cannot deal with strings that contain the character with code 0. We encode chr(0) as chr(1) + chr(1) and chr(1) as chr(1) + chr(2). */ var transl0 = String.fromCharCode(1) + String.fromCharCode(1); var transl1 = String.fromCharCode(1) + String.fromCharCode(2); var encodeZerosRe = new RegExp([+String.fromCharCode(0)+String.fromCharCode(1)+], g); function encodeZeros(s) { return s.replace(encodeZerosRe, function (match) { return (match == String.fromCharCode(0) ? transl0 : transl1);} ); } var decodeZerosRe = new RegExp(String.fromCharCode(1) + ., g); function decodeZeros(msg) { // Decode the 0s msg = msg.replace(decodeZerosRe, function (match) { return (match == transl0 ? String.fromCharCode(0) : String.fromCharCode(1)); }); return msg; } } // AJAX support // @param method String (either POST or GET) // @param contentType String function makeRequest(url, method, contentType, data, datacallback, errorcallback) { //alert(makeRequest url=+url+ method=+method+ contentType=+contentType); var xmlHttpReq = false; if (window.XMLHttpRequest) { // Mozilla/Safari xmlHttpReq = new XMLHttpRequest(); if(contentType && xmlHttpReq.overrideMimeType) { xmlHttpReq.overrideMimeType = contentType; } } else if (window.ActiveXObject) { // IE xmlHttpReq = new ActiveXObject(Microsoft.XMLHTTP); } xmlHttpReq.open(method, url, true); if(contentType) { xmlHttpReq.setRequestHeader(Content-Type, contentType); } // If the data contains \0 Firefox will truncate the data // xmlHttpReq.setRequestHeader(Content-Length, data.length); // The Connection header is refused by Chrome //xmlHttpReq.setRequestHeader(Connection, close) xmlHttpReq.onreadystatechange = function() { if (xmlHttpReq.readyState != 4) return; xmlHttpReq.onreadystatechange = null; // Break the GC cycle if (xmlHttpReq.status == 200) { if(datacallback) { var bytes = xmlHttpReq.responseText; if(isIE && contentType && /octet-stream/.test(contentType) >= 0) { bytes = encodeZeros(GetIEByteArray_ByteStr(xmlHttpReq.responseBody)); } if(0 && window.console) { var now = (new Date().getTime() / 1000).toFixed(3); var debugMsg = [+now+] Received: (len=+bytes.length+): ; for(var i=0;i
Posted on: Mon, 04 Nov 2013 01:37:37 +0000

Trending Topics



>

Recently Viewed Topics




© 2015