1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html>
	<head>
		<script>
			var CreateXHR =
			(
				function CreateCreateXHRScope()
				{
					var CreateXHR = function defaultDummyXHRFn() { return false; };

					if (window.XMLHttpRequest)
						CreateXHR = function createXHRWithNativeRequest() { return new XMLHttpRequest(); };
					else if (window.ActiveXObject)
					{
						try
						{
							new ActiveXObject('Msxml2.XMLHTTP');
							CreateXHR = function createXHRWithAXMSXML2() { return new ActiveXObject('Msxml2.XMLHTTP'); };
						}
						catch (e)
						{
							try
							{
								new ActiveXObject('Microsoft.XMLHTTP');
								CreateXHR = function createXHRWithAXXMLHTTP() { return new ActiveXObject('Microsoft.XMLHTTP'); };
							}
							catch (e) {}
						}
					}

					if (!CreateXHR())
						Debug.Console.error('unable to find a usable transport for performing XHRs');

					return CreateXHR;
				}
			)();

			function errorFn()
			{
				alert('There was an error!');
			}

			var isIE = !!window.attachEvent && (Object.prototype.toString.call(window.opera) !== '[object Opera]');
			var head = document.getElementsByTagName('head')[0];
			var script = document.createElement('script');
			var scriptStr;

			var xhr = CreateXHR();

			xhr.onreadystatechange =
			(
				function stateChange()
				{
					if (xhr.readyState === 4)
					{
						if ((xhr.status >= 200) && (xhr.status < 300)) //we'll say that anything in the 200s is successfull
						{
							scriptStr = 'try {' + xhr.responseText + '} catch (e){errorFn()}';

							if (isIE)
								script.text = scriptStr;
							else
								script.appendChild(document.createTextNode(scriptStr));

							head.appendChild(script);
						}
						else
							errorFn();
					}
				}
			);

			xhr.open('GET', 'testing.js', true);
			xhr.send();
		</script>
	</head>
	<body>
	</body>
</html>