biojs-rest-jsdas/src/jsdas.js
function(url, callback, errorcallback){
		if (!this.initialized) {
			this.initialize();
		}
		var xmlloader = JSDAS.XMLLoader; //get a reference to myself
  
  
		var usingCORS = true;
		var xhr = this.xhrCORS('GET', url);
		if(!xhr) { //if the browser is not CORS capable, fallback to proxy if available
			if(this.proxyURL) {
			    var xhr = this.xhr();
			    xhr.open('GET', this.proxyURL+'?url='+url, true);
			    usingCORS = false;
			} else {
			    errorcallback && errorcallback({id: 'no_proxy', msg: "Cross-Origin requests are not supported but no proxy has been defined"});
			}
		}

		//At this point, we've got a valid XHR
		//xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
		//xhr.setRequestHeader("Accept", "application/xml, text/xml");


		var xmlloader = this; //necessary so the closures get the variable
		var change = function(xhr){
			if (xhr && (xhr.readyState == 4)) {
				if (xmlloader.httpSuccess(xhr)) {
					processResponse(xhr);
				}
				else { //if it failed, it mighht be that the source has no CORS enabled. In such case, fallback to proxy before erroring
					if(usingCORS && xmlloader.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
					  xhr=undefined;
					  usingCORS = false;
					  var new_xhr = xmlloader.xhr();
					  new_xhr.open('GET', xmlloader.proxyURL+'?url='+url, true);
					  new_xhr.onreadystatechange = function() {change(new_xhr);}
					  new_xhr.send(null);
					} else {
					  errorcallback && errorcallback({id: "xmlhttprequest_error", msg: xhr.status});
					}
				}
				//to prevent IE memory leaks
				xhr = undefined;
			} 
		};
		var processResponse = function(xhr) {
			//WARNING: Since Uniprot (and maybe others) do not respond with a correct content-type, we cannot check it here. Should be reactivated as soon as the servers are updated.
			//var ct = xhr.getResponseHeader("content-type");
			//var xml = ct && ct.indexOf("xml") >= 0;
			//if (xml) {
				var data = xhr.responseXML;
				if(!data) { //This block is here since we cannot rely on content type headers
				     errorcallback && errorcallback({id: 'not_xml', msg: "The response was not XML"});
				}
				if(data.documentElement.nodeName != 'parsererror') {
					callback(data);
					return;
				} 
			//} //if anything went wrong, the document was not XML
			//errorcallback && errorcallback({id: 'not_xml', msg: "The response was not XML"});
		};
	
		xhr.onreadystatechange = function() {change(xhr);};

		// Send the data
		try {
			xhr.send(null);

		} catch(e) {
			//This code will rarely be called. Only when there's a problem on sernding the request.
			if(usingCORS && this.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
			      var xhr = this.xhr();
			      xhr.open('GET', this.proxyURL+'?url='+url, true);
			      xhr.onreadystatechange = function() {change(xhr);}
			      try {
				  xhr.send(null);
			      } catch(e) {
				  errorcallback && errorcallback({id: 'sending_error', msg: "There was an error when sending the request"});
			      }
			} else {
			      errorcallback && errorcallback({id: 'sending_error', msg: "There was an error when sending the request"});
			}
		}	
	}
function(url, callback, errorcallback){
		if (!this.initialized) {
			this.initialize();
		}
		var xmlloader = JSDAS.XMLLoader; //get a reference to myself
  
  
		var usingCORS = true;
		var xhr = this.xhrCORS('GET', url);
		if(!xhr) { //if the browser is not CORS capable, fallback to proxy if available
			if(this.proxyURL) {
			    var xhr = this.xhr();
			    xhr.open('GET', this.proxyURL+'?url='+url, true);
			    usingCORS = false;
			} else {
			    errorcallback && errorcallback({id: 'no_proxy', msg: "Cross-Origin requests are not supported but no proxy has been defined"});
			}
		}

		//At this point, we've got a valid XHR
		//xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
		//xhr.setRequestHeader("Accept", "application/xml, text/xml");


		var xmlloader = this; //necessary so the closures get the variable
		var change = function(xhr){
			if (xhr && (xhr.readyState == 4)) {
				if (xmlloader.httpSuccess(xhr)) {
					processResponse(xhr);
				}
				else { //if it failed, it mighht be that the source has no CORS enabled. In such case, fallback to proxy before erroring
					if(usingCORS && xmlloader.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
					  xhr=undefined;
					  usingCORS = false;
					  var new_xhr = xmlloader.xhr();
					  new_xhr.open('GET', xmlloader.proxyURL+'?url='+url, true);
					  new_xhr.onreadystatechange = function() {change(new_xhr);}
					  new_xhr.send(null);
					} else {
					  errorcallback && errorcallback({id: "xmlhttprequest_error", msg: xhr.status});
					}
				}
				//to prevent IE memory leaks
				xhr = undefined;
			} 
		};
		var processResponse = function(xhr) {
			//WARNING: Since Uniprot (and maybe others) do not respond with a correct content-type, we cannot check it here. Should be reactivated as soon as the servers are updated.
			//var ct = xhr.getResponseHeader("content-type");
			//var xml = ct && ct.indexOf("xml") >= 0;
			//if (xml) {
				var data = xhr.responseXML;
				if(!data) { //This block is here since we cannot rely on content type headers
				     errorcallback && errorcallback({id: 'not_xml', msg: "The response was not XML"});
				}
				if(data.documentElement.nodeName != 'parsererror') {
					callback(data);
					return;
				} 
			//} //if anything went wrong, the document was not XML
			//errorcallback && errorcallback({id: 'not_xml', msg: "The response was not XML"});
		};
	
		xhr.onreadystatechange = function() {change(xhr);};

		// Send the data
		try {
			xhr.send(null);

		} catch(e) {
			//This code will rarely be called. Only when there's a problem on sernding the request.
			if(usingCORS && this.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
			      var xhr = this.xhr();
			      xhr.open('GET', this.proxyURL+'?url='+url, true);
			      xhr.onreadystatechange = function() {change(xhr);}
			      try {
				  xhr.send(null);
			      } catch(e) {
				  errorcallback && errorcallback({id: 'sending_error', msg: "There was an error when sending the request"});
			      }
			} else {
			      errorcallback && errorcallback({id: 'sending_error', msg: "There was an error when sending the request"});
			}
		}	
	}
function ( url , callback , errorcallback ) { if ( ! this . initialized ) { this . initialize ( ) ; } var xmlloader = JSDAS . XMLLoader ; //get a reference to myself var usingCORS = true ; var xhr = this . xhrCORS ( 'GET' , url ) ; if ( ! xhr ) { //if the browser is not CORS capable, fallback to proxy if available if ( this . proxyURL ) { var xhr = this . xhr ( ) ; xhr . open ( 'GET' , this . proxyURL + '?url=' + url , true ) ; usingCORS = false ; } else { errorcallback && errorcallback ( { id : 'no_proxy' , msg : "Cross-Origin requests are not supported but no proxy has been defined" } ) ; } } //At this point, we've got a valid XHR //xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); //xhr.setRequestHeader("Accept", "application/xml, text/xml"); var xmlloader = this ; //necessary so the closures get the variable var change = function ( xhr ) { if ( xhr && ( xhr . readyState == 4 ) ) { if ( xmlloader . httpSuccess ( xhr ) ) { processResponse ( xhr ) ; } else { //if it failed, it mighht be that the source has no CORS enabled. In such case, fallback to proxy before erroring if ( usingCORS && xmlloader . proxyURL ) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy xhr = undefined ; usingCORS = false ; var new_xhr = xmlloader . xhr ( ) ; new_xhr . open ( 'GET' , xmlloader . proxyURL + '?url=' + url , true ) ; new_xhr . onreadystatechange = function ( ) { change ( new_xhr ) ; } new_xhr . send ( null ) ; } else { errorcallback && errorcallback ( { id : "xmlhttprequest_error" , msg : xhr . status } ) ; } } //to prevent IE memory leaks xhr = undefined ; } } ; var processResponse = function ( xhr ) { //WARNING: Since Uniprot (and maybe others) do not respond with a correct content-type, we cannot check it here. Should be reactivated as soon as the servers are updated. //var ct = xhr.getResponseHeader("content-type"); //var xml = ct && ct.indexOf("xml") >= 0; //if (xml) { var data = xhr . responseXML ; if ( ! data ) { //This block is here since we cannot rely on content type headers errorcallback && errorcallback ( { id : 'not_xml' , msg : "The response was not XML" } ) ; } if ( data . documentElement . nodeName != 'parsererror' ) { callback ( data ) ; return ; } //} //if anything went wrong, the document was not XML //errorcallback && errorcallback({id: 'not_xml', msg: "The response was not XML"}); } ; xhr . onreadystatechange = function ( ) { change ( xhr ) ; } ; // Send the data try { xhr . send ( null ) ; } catch ( e ) { //This code will rarely be called. Only when there's a problem on sernding the request. if ( usingCORS && this . proxyURL ) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy var xhr = this . xhr ( ) ; xhr . open ( 'GET' , this . proxyURL + '?url=' + url , true ) ; xhr . onreadystatechange = function ( ) { change ( xhr ) ; } try { xhr . send ( null ) ; } catch ( e ) { errorcallback && errorcallback ( { id : 'sending_error' , msg : "There was an error when sending the request" } ) ; } } else { errorcallback && errorcallback ( { id : 'sending_error' , msg : "There was an error when sending the request" } ) ; } } }
This function loads an external XML using a proxy on the server to comply with the SOP

@param {Object} url
@param {Object} callback
This function loads an external XML using a proxy on the server to comply with the SOP