<input type="button" onclick="odesli('http://localhost/www/js-request.htm',prijmi);" value="Zobrazit zdrojovy kod">
<div id="xxx"></div>

<script>
function isFunction(obj) {return typeof(obj)=='function';}//) && obj!=null

function escapeHtml(str) {
    var map = {
        "&": "&amp;",
        "<": "&lt;",
        ">": "&gt;",
        "\"": "&quot;",
        "'":  "&apos;"
    };
    return str.replace(/[&<>"']/g, function(m) { return map[m]; });
}

function odesli(path, onsuccess, onerror)
	{
	var fn;
	req = new XMLHttpRequest();
	fn = {};
	fn.onsuccess   = isFunction(onsuccess) ? onsuccess : function(data){};
	fn.onerror     = isFunction(onerror)   ? onerror   : function(data){alert("Request error\n"+req.error_path+"\n"+req.status)};
			req.onreadystatechange = function()
				{
				if (req.readyState==4 && req.status==200)
					{fn.onsuccess(req.responseText);}
				else	{fn.onerror(req);}
				}

	req.response   = 'responseText';
//	req.onload     = fn.onsuccess;
	req.onerror    = fn.onerror;
	req.error_path = path;
	req.open('GET', path, true);
	req.send();
	}

function prijmi(event)
	{
	var data;
	data = event.target.result ? event.target.result : (req.response ? req.response : '');
	document.getElementById('xxx').innerHTML = '<pre>'+escapeHtml(data)+'<\/pre>';
	}

var req;
</script>
