myRequest.js
/**
 * The myRequest is Javascript object of the cross-browser XMLHttpRequest wrapper. Your request code to the server is very simple, if you are using myRequest obect.
 * Author: Andrej Hristoliubov
 * email: anhr@mail.ru
 * About me: http://anhr.github.io/AboutMe/
 * source: https://github.com/anhr/myRequest
 * example: http://anhr.github.io/myRequest/
 * Licences: GPL, The MIT License (MIT)
 * Copyright: (c) 2015 Andrej Hristoliubov
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 * Revision:
 *  2015-09-04, : 
 *       + myRequest from var to function
 *  2015-08-28, : 
 *       + Cosmetic changes
 *
 */
The myRequest is Javascript object of the cross-browser XMLHttpRequest wrapper. Your request code to the server is very simple, if you are using myRequest obect.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


The myRequest is Javascript object of the cross - browser XMLHttpRequest wrapper . Your request code to the server is very simple if you are using myRequest obect . Permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files ( the " Software " ) to deal in the Software without restriction including without limitation the rights to use copy modify merge publish distribute sublicense and / or sell copies of the Software and to permit persons to whom the Software is furnished to do so subject to the following conditions : The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software .
function myRequest(data){
	this.loadXMLDoc = function(){
		var req;
		if (window.XMLHttpRequest){
			req = new XMLHttpRequest();
			if (!req)
				throw "new XMLHttpRequest() failed!"
		}
		else if (window.ActiveXObject){
			req = this.NewActiveXObject();
			if (!req)
				throw "NewActiveXObject() failed!"
		}
		else throw "myRequest.loadXMLDoc(...) failed!";
		return req;
	}
	this.NewActiveXObject = function(){
	  try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
		catch(e) {}
	  try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
		catch(e) {}
	  try { return new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e) {}
	  try { return new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(e) {}
	  ErrorMessage('This browser does not support XMLHttpRequest. Probably, your security settings do not allow Web sites to use ActiveX controls installed on your computer. Refresh your Web page to find out the current status of your Web page or enable the "Initialize and script ActiveX controls not marked as safe" and "Run Active X controls and plug-ins" of the Security settings of the Internet zone of your browser.');
	  return null;
	}
	this.XMLHttpRequestStart = function (onreadystatechange, async) {
		this.XMLHttpRequestStop();
		this.req.onreadystatechange = onreadystatechange;
		if("onerror" in this.req){
			this.req.onerror = function(event){
				ErrorMessage("XMLHttpRequest error. url: " + this.url, false, false);
			}
		}
		this.XMLHttpRequestReStart(async);
	}
	this.getUrl = function(){
		if((typeof this.url == 'undefined') || (this.url == null)){
			this.url = "XMLHttpRequest.xml";
		}
		return this.url + (this.params ? this.params : "");
	}
	this.XMLHttpRequestReStart = function (async) {
	    try {
	        if (typeof async == 'undefined')
	            async = true;
	        this.req.open("GET", this.getUrl(), async);
	        if (async) {
	            var timeout = (60 + 30) * 1000;
	            if ("timeout" in this.req)
	                this.req.timeout = timeout;
	            if ("ontimeout" in this.req)
	                this.req.ontimeout = function () {
	                    ErrorMessage('XMLHttpRequest timeout', false, false);
	                }
	            else {
	                clearTimeout(this.timeout_id_SendReq);
	                this.timeout_id_SendReq = setTimeout(function () {
	                    ErrorMessage('XMLHttpRequest timeout 2', false, false);
	                }
				    , timeout);
	            }
	        }
			this.req.send(null);
		}catch(e){
			ErrorMessage(e.message + " url: " + this.url, false, false);
		}
	}
	this.XMLHttpRequestStop = function(){
		if(this.req == null)
			return;
		this.req.abort();
	}
	this.ProcessReqChange = function(processStatus200){
		var req = this.req;
if(!isIE){
}	
		switch(req.readyState)
		{
		case 4:
			{
				if(typeof req.status == "unknown"){
					consoleError('typeof XMLHttpRequest status == "unknown"');
					return true;
				}
				if(req.status == 200)
				{
					clearTimeout(this.timeout_id_SendReq);
					return processStatus200(this);
				}
				else{
				    ErrorMessage("Invalid XMLHttpRequest status : " + req.status + " url: " + this.url + " req.responseText: " + req.responseText);
				}
			}
			break;
		case 1:
		case 2:
		case 3:
			break;
		case 0:
		default:
			throw "processReqChange(); req.readyState = " + req.readyState;
			break;
		}
		return true;
	}
	this.processStatus200Error = function(){
		var error = this.GetElementText('error', true);
		if(error)
		{
			ErrorMessage(error);
			return true;
		}
		return false;
	}
	this.GetElementText = function(tagName, noDisplayErrorMessage){
		var xmlhttp = this.req;
		if(!xmlhttp.responseXML){
			if(noDisplayErrorMessage != true)
				ErrorMessage('GetXMLElementText(xmlhttp, ' + tagName + '); xmlhttp.responseXML is null.\nxmlhttp.responseText:\n' + xmlhttp.responseText);
			return null;
		}
		var element = xmlhttp.responseXML.getElementsByTagName(tagName);
		if(element.length == 0){
			if(noDisplayErrorMessage != true)
				ErrorMessage('GetXMLElementText(xmlhttp, "' + tagName + '"); element.length == ' + element.length);
			return "";
		}
		var text = "";
		for(var i = 0; i < element.length; i++){
			if(typeof(element[i].textContent) == 'undefined')
			{
				if(typeof(element[i].text) == 'undefined')
				{
					ErrorMessage('GetXMLElementText(xmlhttp, ' + tagName + '); element[' + i + '].text) == undefined');
					return '';
				}
				if(text != "")
					text += " ";
				text += element[i].text;
			}
			else text += element[i].textContent;
		}
		return text;
	}
	if(data){
		this.req = data.req;
		this.url = data.url;
		this.params = data.params;
	}else{
		try{
			this.req = this.loadXMLDoc();
		} catch(e) {
			var message;
			if(typeof e.message == 'undefined')
				message = e;
			else message = e.message;
			ErrorMessage("Your browser is too old and is not compatible with our site.\n\n"
				+ window.navigator.appName + " " + window.navigator.appVersion + "\n\n" + message);
			return;
		}
	}
	if(!this.req){
		consoleError("Invalid myRequest.req: " + this.req);
		return;
	}
}
function myRequest ( data ) { this . loadXMLDoc = function ( ) { var req ; if ( window . XMLHttpRequest ) { req = new XMLHttpRequest ( ) ; if ( ! req ) throw "new XMLHttpRequest() failed!" } else if ( window . ActiveXObject ) { req = this . NewActiveXObject ( ) ; if ( ! req ) throw "NewActiveXObject() failed!" } else throw "myRequest.loadXMLDoc(...) failed!" ; return req ; } this . NewActiveXObject = function ( ) { try { return new ActiveXObject ( "Msxml2.XMLHTTP.6.0" ) ; } catch ( e ) { } try { return new ActiveXObject ( "Msxml2.XMLHTTP.3.0" ) ; } catch ( e ) { } try { return new ActiveXObject ( "Msxml2.XMLHTTP" ) ; } catch ( e ) { } try { return new ActiveXObject ( "Microsoft.XMLHTTP" ) ; } catch ( e ) { } ErrorMessage ( 'This browser does not support XMLHttpRequest. Probably, your security settings do not allow Web sites to use ActiveX controls installed on your computer. Refresh your Web page to find out the current status of your Web page or enable the "Initialize and script ActiveX controls not marked as safe" and "Run Active X controls and plug-ins" of the Security settings of the Internet zone of your browser.' ) ; return null ; } this . XMLHttpRequestStart = function ( onreadystatechange , async ) { this . XMLHttpRequestStop ( ) ; this . req . onreadystatechange = onreadystatechange ; if ( "onerror" in this . req ) { this . req . onerror = function ( event ) { ErrorMessage ( "XMLHttpRequest error. url: " + this . url , false , false ) ; } } this . XMLHttpRequestReStart ( async ) ; } this . getUrl = function ( ) { if ( ( typeof this . url == 'undefined' ) || ( this . url == null ) ) { this . url = "XMLHttpRequest.xml" ; } return this . url + ( this . params ? this . params : "" ) ; } this . XMLHttpRequestReStart = function ( async ) { try { if ( typeof async == 'undefined' ) async = true ; this . req . open ( "GET" , this . getUrl ( ) , async ) ; if ( async ) { var timeout = ( 60 + 30 ) * 1000 ; if ( "timeout" in this . req ) this . req . timeout = timeout ; if ( "ontimeout" in this . req ) this . req . ontimeout = function ( ) { ErrorMessage ( 'XMLHttpRequest timeout' , false , false ) ; } else { clearTimeout ( this . timeout_id_SendReq ) ; this . timeout_id_SendReq = setTimeout ( function ( ) { ErrorMessage ( 'XMLHttpRequest timeout 2' , false , false ) ; } , timeout ) ; } } this . req . send ( null ) ; } catch ( e ) { ErrorMessage ( e . message + " url: " + this . url , false , false ) ; } } this . XMLHttpRequestStop = function ( ) { if ( this . req == null ) return ; this . req . abort ( ) ; } this . ProcessReqChange = function ( processStatus200 ) { var req = this . req ; if ( ! isIE ) { } switch ( req . readyState ) { case 4 : { if ( typeof req . status == "unknown" ) { consoleError ( 'typeof XMLHttpRequest status == "unknown"' ) ; return true ; } if ( req . status == 200 ) { clearTimeout ( this . timeout_id_SendReq ) ; return processStatus200 ( this ) ; } else { ErrorMessage ( "Invalid XMLHttpRequest status : " + req . status + " url: " + this . url + " req.responseText: " + req . responseText ) ; } } break ; case 1 : case 2 : case 3 : break ; case 0 : default : throw "processReqChange(); req.readyState = " + req . readyState ; break ; } return true ; } this . processStatus200Error = function ( ) { var error = this . GetElementText ( 'error' , true ) ; if ( error ) { ErrorMessage ( error ) ; return true ; } return false ; } this . GetElementText = function ( tagName , noDisplayErrorMessage ) { var xmlhttp = this . req ; if ( ! xmlhttp . responseXML ) { if ( noDisplayErrorMessage != true ) ErrorMessage ( 'GetXMLElementText(xmlhttp, ' + tagName + '); xmlhttp.responseXML is null.\nxmlhttp.responseText:\n' + xmlhttp . responseText ) ; return null ; } var element = xmlhttp . responseXML . getElementsByTagName ( tagName ) ; if ( element . length == 0 ) { if ( noDisplayErrorMessage != true ) ErrorMessage ( 'GetXMLElementText(xmlhttp, "' + tagName + '"); element.length == ' + element . length ) ; return "" ; } var text = "" ; for ( var i = 0 ; i < element . length ; i ++ ) { if ( typeof ( element [ i ] . textContent ) == 'undefined' ) { if ( typeof ( element [ i ] . text ) == 'undefined' ) { ErrorMessage ( 'GetXMLElementText(xmlhttp, ' + tagName + '); element[' + i + '].text) == undefined' ) ; return '' ; } if ( text != "" ) text += " " ; text += element [ i ] . text ; } else text += element [ i ] . textContent ; } return text ; } if ( data ) { this . req = data . req ; this . url = data . url ; this . params = data . params ; } else { try { this . req = this . loadXMLDoc ( ) ; } catch ( e ) { var message ; if ( typeof e . message == 'undefined' ) message = e ; else message = e . message ; ErrorMessage ( "Your browser is too old and is not compatible with our site.\n\n" + window . navigator . appName + " " + window . navigator . appVersion + "\n\n" + message ) ; return ; } } if ( ! this . req ) { consoleError ( "Invalid myRequest.req: " + this . req ) ; return ; } }
The myRequest is Javascript object of the cross-browser XMLHttpRequest wrapper.
The myRequest is Javascript object of the cross - browser XMLHttpRequest wrapper .
//	this.url = url; //For compatibility with IE Windows Phone //ATTENTION!!! do not works in IE //			throw "myRequest.url = " + myRequest.url + " failed!"; //Внимание!!! Задержка должна быть больше CSocketWaitEvent::WaitResponse //for IE6 //for Safari, IE6 //consoleLog("setTimeout this.req.timeout_id_SendReq = " + this.req.timeout_id_SendReq); //consoleLog("XMLHttpRequestStop(...)"); //	consoleLog("processReqChange(); req.statusText: " + req.statusText + ". req.status = " + req.status + ". req.readyState = " + req.readyState + ". req.responseText: " + req.responseText); // only if req shows "complete" //http://www.w3schools.com/ajax/ajax_xmlhttprequest_onreadystatechange.asp //http://xmlhttprequest.ru/w3c //request finished and response is ready //IE5 timeout //Я не могу вставлять switch один в другой //OK) //200://OK //server connection established //request received //processing request //		case 404: //request not initialized //switch(req.readyState) //ATTENTION!!! For IE set the content-type m_HttpResponse.SetContentType("text/xml"); //IE //Chrome