Created
March 24, 2014 13:12
-
-
Save cleuton/9739795 to your computer and use it in GitHub Desktop.
Old Ajax MS IE Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>*** Ajax básico ***</title> | |
| <script> | |
| function iniciaRequest(url) { | |
| // Teste do Browser | |
| if(window.XMLHttpRequest) { | |
| // Não é MS Internet Explorer | |
| obj = new XMLHttpRequest(); | |
| obj.onreadystatechange = resposta; | |
| try { | |
| obj.open("GET", url, true); | |
| obj.send(null); | |
| } | |
| catch(exc) { | |
| alert("Exception: " + exc); | |
| } | |
| } | |
| else if(window.ActiveXObject) { | |
| // É MS Internet Explorer | |
| obj = new ActiveXObject("Microsoft.XMLHTTP"); | |
| obj.onreadystatechange = resposta; | |
| obj.open("GET", url, true); | |
| obj.send(); | |
| } | |
| else { | |
| // Esqueça Ajax | |
| alert("seu navegador não suporta Ajax"); | |
| return; | |
| } | |
| } | |
| function resposta() { | |
| if(obj.readyState == 4) { | |
| // fim da resposta | |
| if(obj.status == 200) { | |
| // HTTP status OK ? | |
| // Manipulação do XML para apresentação | |
| imp = document.getElementById("saida"); | |
| imp.innerHTML = "<ul>"; | |
| resposta = obj.responseXML; | |
| produtos = resposta.getElementsByTagName("produto"); | |
| for(ix=0; ix<produtos.length; ix++) { | |
| var valor = produtos[ix].textContent; | |
| if(!valor) { | |
| // MS Internet Explorer tem a propriedade "text" | |
| valor = produtos[ix].text; | |
| } | |
| imp.innerHTML = imp.innerHTML + | |
| "<li>" + | |
| valor + | |
| "</li>"; | |
| } | |
| imp.innerHTML = imp.innerHTML + "</ul>"; | |
| } | |
| } | |
| } | |
| </script> | |
| <body onload="iniciaRequest('http://localhost/teste.xml');"> | |
| <h3>Produtos</h3> | |
| <div id="saida"> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment