Código HTML:
Ver original
Código Javascript:
Ver original
<script type="text/javascript"> var botones = document.getElementsByClassName("enviar"), total = botones.length, salida = document.getElementById("salida"); for (i = 0; i < total; i++) { botones[i].addEventListener("click", function(){ var ajax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") || new ActiveXObject("Msxml2.XMLHTTP"); ajax.open("POST", "ejemplo.php", true); ajax.onreadystatechange = function(){ if (ajax.readyState == 4) { switch (ajax.status) { case 200: salida.innerHTML = ajax.responseText; break; case 404: salida.innerHTML = "La dirección brindada no existe"; break; default: salida.innerHTML = ajax.status; break; } } }; ajax.send(this.value); }, false); } </script>