Ver Mensaje Individual
  #10 (permalink)  
Antiguo 01/09/2010, 10:47
fvelazquez
 
Fecha de Ingreso: agosto-2009
Mensajes: 10
Antigüedad: 15 años, 6 meses
Puntos: 0
Desacuerdo Respuesta: Crear DataGrid en JSP

Mmmm que mal, ahora es otro problema,

Cuando llamo al método que crea el XML la primera vez funciona correctamente, pero despues que actualizo los datos en la BD, la página no actualiza la información cuando llamo el método de nuevo, será que me falta algo y no lo se aun?

METODOS AJAX

Código PHP:
Ver original
  1. <script>
  2.  
  3. function funcionCallback4()
  4. {
  5.     // Comprobamos si la peticion se ha completado (estado 4)
  6.     if( ajax4.readyState == 4 )
  7.     {
  8.         // Comprobamos si la respuesta ha sido correcta (resultado HTTP 200)
  9.  
  10.         //if( ajax4.status == 200 )
  11.         //{
  12.             // Escribimos el resultado en la pagina HTML mediante DHTML
  13.             //document.all.grid_COSE041.innerHTML = "<b>"+ajax4.responseText+"</b>";
  14.  
  15.  
  16.                         try
  17.                         {
  18.                         document.all.lbl_Mensaje.innerHTML ="";
  19.                         var xml = ajax4.responseXML;
  20.                         var i=0;
  21.                         var cant = xml.getElementsByTagName('EMPNUM').length;
  22.                         var respuesta;
  23.                         if(tip=='A')
  24.                             {
  25.                                 respuesta = "<table id=\"COSE041\" border=2><thead><tr><th>INACTIVAR</th><th>FOLIO</th><th>NOMBRE</th>"+
  26.                                     "</thead><tbody>";
  27.                         }
  28.                         else
  29.                             {
  30.                                 respuesta = "<table id=\"COSE041\" border=2><thead><tr><th>ACTIVAR</th><th>FOLIO</th><th>NOMBRE</th>"+
  31.                                     "</thead><tbody>";
  32.                             }
  33.                         var semiresp;
  34.                         for(i=0;i<cant;i++)
  35.                         {
  36.                             var resp = "<tr>";
  37.                             var id = xml.getElementsByTagName('EMPNUM').item(i).getAttribute('id');
  38.                             if(tip=='A')
  39.                             {
  40.                                 resp = resp + "<td><img alt=Consultar  src=imagenes/equis.png onClick=activar('" + id + "','I');></td>";
  41.                             }
  42.                             else
  43.                             {
  44.                                 resp = resp + "<td><img alt=Consultar  src=imagenes/cambiar.png onClick=activar('" + id + "','A');></td>";
  45.                             }
  46.                             resp = resp + "<td>"+ id + "</td>";
  47.                             resp = resp + "<td>"+ xml.getElementsByTagName('EMPNOM')[i].firstChild.data + "</td>";
  48.  
  49.                             resp = resp + "</tr>";
  50.                             if (i==0)
  51.                             {
  52.                                 semiresp = resp;
  53.                             }
  54.                             else
  55.                             {
  56.                                 semiresp = semiresp + resp;
  57.                             }
  58.                         }
  59.                 }
  60.                 catch(e)
  61.                 {
  62.                     alert(e.toString());
  63.                 }
  64.  
  65.                 document.all.lbl_Mensaje.innerHTML = respuesta + semiresp + "</tboby></table>";
  66.         //}
  67.     }
  68. }
  69.  
  70. function grid_COSE041(TIPO)
  71. {
  72.     // Creamos el control XMLHttpRequest segun el navegador en el que estemos
  73.     if( window.XMLHttpRequest )
  74.         ajax4 = new XMLHttpRequest(); // No Internet Explorer
  75.     else
  76.         ajax4 = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer
  77.  
  78.     // Almacenamos en el control al funcion que se invocara cuando la peticion
  79.     // cambie de estado
  80.     ajax4.onreadystatechange = funcionCallback4;
  81.         tip = TIPO;
  82.     // Enviamos la peticion
  83.         ajax4.open( "GET", "gridCOSE041.jsp?SIENUM="+document.all.txt_siembra.value+"&TIPO="+TIPO, true);
  84.         ajax4.send( "" );
  85. }
  86.  
  87. </script>

CREO XML

Código PHP:
Ver original
  1. <%@page contentType="text/xml" pageEncoding="UTF-8"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  3.    "http://www.w3.org/TR/html4/loose.dtd">
  4.  
  5. <%
  6.     HttpSession sesion = request.getSession();
  7.     String id_usuario = (String)sesion.getAttribute("id_usuario");
  8.     String password = (String)sesion.getAttribute("password");
  9.     String SIENUM = request.getParameter("SIENUM");
  10.     String TIPO = request.getParameter("TIPO");
  11.     Acceso acceso = new Acceso();
  12.     String respuestaXML;
  13.     respuestaXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
  14.     String cadena = "";
  15.     if(TIPO.equals("A"))
  16.         {
  17.            // Este metodo me devuelve el resultado de la sentencia SQL
  18.             cadena = acceso.grid_COSE041(SIENUM, id_usuario, password);
  19.         }
  20.     else
  21.         {
  22.             // Este metodo me devuelve el resultado de la sentencia SQL
  23.             cadena = acceso.grid_COSE041A(SIENUM, id_usuario, password);
  24.         }
  25.     String cuerpo ="";
  26.     String respuesta = "";
  27.         Boolean v=true;
  28.         try{
  29.             String [] temp = cadena.split("@");
  30.             for (String algo : temp){
  31.                 String [] temp1 = algo.split("#");
  32.                 if (v) {
  33.                     cuerpo ="<EMPNUM id=\""+temp1[0]+"\"><EMPNOM>"+temp1[1]+"</EMPNOM>" + "</EMPNUM>";
  34.                     v=false;
  35.                 }else{
  36.                     cuerpo =cuerpo + "<EMPNUM id=\"" + temp1[0] + "\"><EMPNOM>"+temp1[1].trim() + "</EMPNOM>" + "</EMPNUM>";
  37.                 }
  38.             }
  39.             respuesta = "<COSE041>" + cuerpo + "</COSE041>";
  40.         }catch(Exception e){
  41.             respuestaXML = e.toString();
  42.         }
  43.         out.print(respuestaXML + respuesta);
  44. %>

Disculpen las molestias