Advertisement
MarioCares

Dale con Ajax - JavaScript

Apr 27th, 2011
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ObjAJAX(){
  2.     var obj;
  3.     if (window.XMLHttpRequest)
  4.         obj = new XMLHttpRequest();
  5.     else if (window.ActiveXObject){
  6.         try{
  7.             obj = new ActiveXObject("Msxml2.XMLHTTP");
  8.         }
  9.         catch(e){
  10.             try{
  11.                 obj = new ActiveXObject("Microsoft.XMLHTTP");
  12.             }catch(e){
  13.                 alert("Error al generar objeto XMLHttpRequest");
  14.             }
  15.         }
  16.     }
  17.     return obj;
  18. }
  19.  
  20. function getEgr(){
  21.     oxml = ObjAJAX();
  22.     oxml.open('GET', 'Egresos?accion=leer&fin=getEgreso&egr='+this.value, true);
  23.     oxml.onreadystatechange = function(){
  24.         if(oxml.readyState == 4){
  25.             var xml = oxml.responseXML;
  26.             document.getElementById("fecha").value = xml.getElementsByTagName("fecha").item(0).getAttribute("dato");
  27.         }else{
  28.             /*mientras espero respuesta, por ejemplo, puedo poner un gif de carga*/
  29.             <img src="cargando.gif" />
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement