All pastes #1725346 Raw Edit

documento 1

public text v1 · immutable
#1725346 ·published 2009-12-23 22:11 UTC
rendered paste body
<html>
	<body>
		<div id="div" style="border: 1px groove;width:320px;height:100px;">
			<!-- dinamico -->
		</div>
		<hr/>
		<button id="btn">Carregar conteúdo dinâmico</button>
		<script>
			//nosso utilitário
			function XHR(uri, dest, hook) {
				var x = typeof XMLHttpRequest == "undefined" ? //
				new ActiveXObject("Microsoft.XMLHTTP")
						: new XMLHttpRequest();

				x.onreadystatechange = function() {
					if (x.readyState == 4) {
						dest.innerHTML = x.responseText
						if (hook)
							hook();
					}
				};

				this.carregar = function() {
					x.open("GET", uri, true);
					x.send();
				}
			}
			
			var div = document.getElementById("div");
			
			var botao = document.getElementById("btn");
			
			botao.onclick=function(){
				new XHR("trecho.html",div).carregar();
				var tag = document.createElement("script");
				tag.src="trecho.js";
				document.body.appendChild(tag);
			};						
		</script>
	</body>
</html>