Usando HTML5 y javascript
Aqui un pequeño ejemplo del tradicional juego "Serpientes y Escaleras" implementando canvas y XMLHttpRequest para la obtencion de datos de un archivo fuente en .txt
Aqui la funcion utilizada en javascript:
//variables globales
var datos, totalFilas;
function cargarPreguntas() { var xmlhttp; if(window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { datos = xmlhttp.responseText.split("\n"); //\n indica fin de linea totalFilas = datos.length; } } xmlhttp.open("GET","clases/Datos.txt",true); xmlhttp.send(); }Demo: Ver aquí
No hay comentarios:
Publicar un comentario