Introduction to Ajax

Page 231

Introducci贸n a AJAX

Cap铆tulo 14. Ejercicios resueltos

var municipios = eval('(' + peticion.responseText + ')'); lista.options.length = 0; var i=0; for(var codigo in municipios) { lista.options[i] = new Option(municipios[codigo], codigo); i++; } } } } window.onload = function() { peticion = inicializa_xhr(); if(peticion) { peticion.onreadystatechange = muestraProvincias; peticion.open("GET", "http://localhost/RUTA_HASTA_ARCHIVO/ cargaProvinciasJSON.php?nocache="+Math.random(), true); peticion.send(null); } document.getElementById("provincia").onchange = cargaMunicipios; } </script> </head> <body> <h1>Listas desplegables encadenadas</h1> <form> <label for="provincia">Provincia</label> <select id="provincia"> <option>Cargando...</option> </select> <br/><br/> <label for="municipio">Municipio</label> <select id="municipio"> <option>- selecciona una provincia -</option> </select> </form> </body> </html>

14.18. Ejercicio 18 El archivo util.js que utiliza el ejercicio se incluye en el archivo ZIP de la soluci贸n completa. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/ xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

www.librosweb.es

231


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.