Foros del Web » Programando para Internet » Javascript »

Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

Estas en el tema de Este Script se ejecuta 1 sola vez ajax.responseText.. Why? en el foro de Javascript en Foros del Web. Holas a tod@s, Tengo un formulario que se compone de las siguientes partes: 1 div con id="formulario" que presenta un formulario para ser diligenciado 1 ...
  #1 (permalink)  
Antiguo 06/11/2011, 13:20
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Pregunta Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

Holas a tod@s,

Tengo un formulario que se compone de las siguientes partes:
1 div con id="formulario" que presenta un formulario para ser diligenciado
1 div con id="botones" que contiene botones
1 div con id="reporte" contenedor de las respuestas devueltas por ajax

Código PHP:
<!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">
  <
head>
    <
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <
title>Definici&oacuten de Reportes</title>
    <
meta name="description" />
    <
style type="text/css">
    .
clasetbl {
    
border-width1pt;
    
border-color#000000;
        
background-color white;
    }
    .
claseinput {
         
border-style solid;
         
border-width 0.5px;
         
font-size    11px;
         
font-weight  bold;
         
color        #000000;
         
font-family  verdana,arial;
    }
    .
clasetd {
         
font-size    12px;
         
font-weight  bold;
         
color        #000000;
         
font-family  verdana,arial;
    }
    .
clasebody {
       
background-color #F2F2F2;
       
font-family arial;
    }
    </
style>
    <
script language="javascript" src="datagrid1.js" type="application/javascript"></script>
  </head>

  <body class="clasebody">
    <table cellspacing="0" cellpadding="0">
      <table cellspacing="0">  
        <form name="forma" method="post">
          <div id="formulario" name="formulario" cellspacing="0" cellpadding="0">
              <tr>
                <td class="clasetd">Codigo Reporte:
                </td>
                <td>
                  <input type="text" id="codigo" name="codigo" value="" class="claseinput" style="width:50px;" onChange="fDatos('formulario','buscar');">
                </td>
              </tr>
              <tr>
                <td class="clasetd">Nombre Reporte:
                </td>
                <td>
                  <input type="text" id="nombre" name="nombre" value="" class="claseinput" style="width:450px;">
                </td>
              </tr>
              <tr>
                <td class="clasetd">Grupos de Columnas:
                </td>
                <td>
                  <input type="text" id="grupos" name="grupos" value="" class="claseinput" style="width:30px;">
                </td>
              <tr>
                <td class="clasetd">Nro. Columnas:
                </td>
                <td>
                  <input type="text" id="cols" name="cols" value="" class="claseinput" style="width:30px;" onChange="javascript: crearFilas();">
                </td>
              </tr>
          </div>

          <tr></tr>
          <div id="botones" style="display=none">
            <tr>
              <td colspan="2"><input type="button" value="Grabar" id="graba" name="accion" onClick="fDatos('reporte','grabar');" style="background-color: #738EB5; height: 18; font-size: 8 pt; font-weight: bold; color: ffffff; border-style: solid; border-width: 1">
              <input type="button" value="Reportar" id="repor" name="accion" onClick="fDatos('reporte','repor');" style="background-color: #738EB5; height: 18; font-size: 8 pt; font-weight: bold; color: ffffff; border-style: solid; border-width: 1"></td>
            </tr>
          </div>

          <div border="0" id="reporte" name="reporte" cellspacing="0"  cellpadding="0" background="white">
            <tr></tr>
          </div>

        </form>
      </table>
    </table>
  </body>
</html> 
Al activarse el evento onChange en el input código mediante ajax, con el método post, consulta la BD para verificar la existencia del reporte, de ser así el servidor devuelve los demás campos del formulario.
Luego de obtener el resultado se hace click sobre el boton Reportar que también por ajax se debe hacer el llamado al mismo script php del paso anterior pero no lo hace. He verificado la url y el queryString y los veo bien pero no ejecuta el script php.... primer Por qué será?

Este es el script de ajax
Código PHP:
function nuevoAjax()
{
  var 
xmlhttp=false;
  try
  {
       
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (
e)
  {
       try
       {
             
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       catch (
e)
       {
             
xmlhttp false;
       }
  }

  if (!
xmlhttp && typeof XMLHttpRequest!='undefined')
  {
       
xmlhttp = new XMLHttpRequest();
  }
  return 
xmlhttp;
}

function 
fDatos(contenedor,boton)
{

  
ss document.getElementById("reporte");
  
ss.style.display='none';
  var 
objTbl document.getElementById(contenedor);
  var 
objErr document.getElementById("estado");
  switch (
boton) {
     case 
"grabar":
        var 
url "genreport.php";
     break;
     case 
"repor":
     case 
"buscar":
        var 
url "procesa_repor.php";
     break;
  }
alert(url);

  
ajax nuevoAjax();

  
ajax.open("POST"urltrue);

  
ajax.onreadystatechange = function()
  {
      switch (
ajax.readyState)
      {
            case 
0:
                 
objTbl.innerHTML 'Error 0. No se ha abierto la comunicaci&oacute;n.';
                 break;
            case 
1:
                 
objTbl.innerHTML="<img src='./imagenes/ajax-loader.gif'>"+" Procesando su peticion, un momento por favor...";
                 break;
            case 
2:
                 
objTbl.innerHTML 'Petici&oacute;n cargada, esperando respuesta del servidor...';
                 break;
            case 
3:
                 
objTbl.innerHTML '';
                 break;
            case 
4:
                 if (
ajax.status == 200) {
                    
ver document.getElementById("formulario");
                    
ver.style.display 'block';
                    
objTbl.innerHTML ajax.responseText;
                 }
                 else
                    
objTbl.innerHTML 'Error 200';
                 break;
      }
  }

  var 
qString;

  
ajax.setRequestHeader("Content-Type""application/x-www-form-urlencoded");
  if (
boton != "grabar") {
     
repor document.getElementById("codigo").value;
     
qString "codigo="+repor+"&accion="+boton;
  }
  else {
     
grp document.getElementById("grupos").value;
     
col document.getElementById("cols").value;
     
qString arma_queryString(grp,col,boton);
     
qString qString+"&codigorep="+document.getElementById('codigo').value+"&nombre="+document.getElementById("nombre").value+"&subgrp=0";
  }
alert(qString);
  
ajax.send(qString);

  function 
arma_queryString(grpscolsboton) {
      
grupos "";
      
columnas "";
      
tit document.getElementById('tit0').value;
      
stit document.getElementById('tit1').value;
      
qString "tit0="+tit+"&stit="+stit+"&";
      
qString qString+"grp="+grps+"&cols="+cols;
      
grpid = new Array();
      for (
i=1i<=grpsi++) {
          
grpid "grp"+i+"_0";
          
tgrp document.getElementById(grpid).value;
          
"g"+i;
          
qString qString+"&g"+i+"="+tgrp;
      }
      for (
i=1i<=grpsi++) {
          for (
j=0j<=colsj++) {
              if (
j==0)
                 
clpid="c0_0";
              else
                 
clpid "c"+j+"_"+i;
              
tcol document.getElementById(clpid).value;
              
qString qString+"&"+clpid+"="+tcol;
              if (
j==0)
                 
selid="s0_0";
              else
                 
selid "s"+j+"_"+i;
              
tsel document.getElementById(selid).value;
              
qString qString+"&"+selid+"="+tsel;
              if (
j==0)
                 
txtid="t0_0";
              else
                 
txtid "t"+j+"_"+i;
              
ttxt document.getElementById(txtid).value;
              
qString qString+"&"+txtid+"="+ttxt;
          }
      }
      
qString qString+"&accion="+boton;
      return 
qString;
  }

Otra cosa, cuando ajax recibe la respuesta del primer paso, la idea es que muestre en pantalla tanto el div formulario como el div reporte, esto lo hace pero primero visualiza la respuesta y debajo el formulario, es decir, cambia la posición de los divs... Segundo Por qué será?

Agradezco de antemano la ayuda que puedan brindarme

Un Cordial Saludo,
  #2 (permalink)  
Antiguo 06/11/2011, 13:59
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

vuelvo a decirte lo mismo. dejando aparte la estructura html, el problema seguramente es que estás reutilizando el objeto
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}
  #3 (permalink)  
Antiguo 06/11/2011, 14:06
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Respuesta: Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

Hola de nuevo IsaBelM

Pero por que funciona con el evento onChange y no con el boton? siendo la misma funcion y a la postre el mismo script php que se llama desde ajax y el mismo queryString?
  #4 (permalink)  
Antiguo 06/11/2011, 14:20
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

te lo acabo de decir estás reutilizando el objeto

pd: con el evento onchange invocas crearFilas(), que no aparece por ningún lado
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}
  #5 (permalink)  
Antiguo 06/11/2011, 14:57
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Respuesta: Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

Me explico....

1.<input type="text" id="codigo" name="codigo" value="" class="claseinput" style="width:50px;" onChange="fDatos('formulario','buscar');">
Este es el que digo que me fuciona perfecto: hace el llamado al script php y todo bien

2. <input type="button" value="Reportar" id="repor" name="accion" onClick="fDatos('reporte','repor');" style="background-color: #738EB5; height: 18; font-size: 8 pt; font-weight: bold; color: ffffff; border-style: solid; border-width: 1"></td>
Este es el que digo que no me canciona

En ambos casos armo prácticamente la misma url, solo cambia el nombre del boton o evento que hizo el llamado a la funcion fDatos ----- (buscar para el primer caso y repor para el segundo)

Para cuando ocurre el evento onChange (primer caso) la url que se arma es:
qString=codigorep=XXX&accion=buscar

Para cuando ocurre el click sobre el boton Reportar la url que se arma es:
qString=codigorep=XXX&accion=repor

Para hacer el llamado de ajax:
ajax.open("POST", url, "true)
ajax.send(qString);

La funcion que mencionas crear_fFlas corresponde a otra que se llama desde otro lado del script y funciona perfecto, es decir, no se utiliza por el momento para llamar a los script php

Como digo, cuando hago click sobre el boton reportar estoy seguro de que llega a la funcion fDatos pero no hace el llamado al script php (url = "procesa_repor.php";). Esto lo verifico con alerts que le congo en la funcion fDatos y en ambos casos me muestra los alerts que le he puesto (como se ve en el segundo codigo que he mostrado
Me hago entender?

Gracias por tu interes al respecto
  #6 (permalink)  
Antiguo 06/11/2011, 16:35
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

último intento. declara el objeto como null
Cita:
ajax = null;
a ver si eso lo soluciona

pd: no tienes errores de sintaxis?? parece que te faltan llaves de cierre
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}
  #7 (permalink)  
Antiguo 06/11/2011, 17:40
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Respuesta: Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

Intente dos vainas:

1. colocar al inicio dela funcion fDatos ajax = null. Pailas sigue igual
2. Cambiar el método POST por GET. obviamente cambiando lo necesario en el script php para que leyera como metodo GET. Pailas sigue igual

Como que el patrón me va a echar.... (jejejeje)
  #8 (permalink)  
Antiguo 06/11/2011, 18:03
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Respuesta: Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

Por si las moscas envio el script javascript (PARTE I)

Código PHP:
function nuevoAjax()
{
  var 
xmlhttp=false;
  try
  {
       
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (
e)
  {
       try
       {
             
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       catch (
e)
       {
             
xmlhttp false;
       }
  }

  if (!
xmlhttp && typeof XMLHttpRequest!='undefined')
  {
       
xmlhttp = new XMLHttpRequest();
  }
  return 
xmlhttp;
}

function 
fDatos(contenedor,boton)
{
  
ss document.getElementById("reporte");
  
ss.style.display='none';
  var 
objTbl document.getElementById(contenedor);
  var 
objErr document.getElementById("estado");
  switch (
boton) {
     case 
"grabar":
        var 
url "genreport.php";
     break;
     case 
"producir":
        var 
url "procesa_repor.php";
     break;
     case 
"buscar":
        var 
url "procesa_repor.php";
     break;
     default :
        
alert("Pailas");
     break;
  }

  
ajax nuevoAjax();

  
ajax.open("POST"urltrue);

  
ajax.onreadystatechange = function()
  {
      switch (
ajax.readyState)
      {
            case 
0:
                 
objTbl.innerHTML 'Error 0. No se ha abierto la comunicaci&oacute;n.';
                 break;
            case 
1:
                 
objTbl.innerHTML="<img src='./imagenes/ajax-loader.gif'>"+" Procesando su peticion, un momento por favor...";
                 break;
            case 
2:
                 
objTbl.innerHTML 'Petici&oacute;n cargada, esperando respuesta del servidor...';
                 break;
            case 
3:
                 
objTbl.innerHTML '';
                 break;
            case 
4:
                 if (
ajax.status == 200) {
                    if (
boton == "buscar") {
                       
document.getElementById("nombre").value ajax.responseText;
                       
ver document.getElementById("resporte");
                       
ver.style.display 'none';
                    }
                    else {
                       
ver document.getElementById("formulario");
                       
ver.style.display 'block';
                       
objTbl.innerHTML ajax.responseText;
                    }
                 }
                 else
                    
objTbl.innerHTML 'Error 200';
                 break;
      }
  }

  var 
qString;

  
ajax.setRequestHeader("Content-Type""application/x-www-form-urlencoded");
  if (
boton != "grabar") {
     
repor document.getElementById("codigo").value;
     
qString "codigo="+repor+"&accion="+boton;
  }
  else {
     
grp document.getElementById("grupos").value;
     
col document.getElementById("cols").value;
     
qString arma_queryString(grp,col,boton);
     
qString qString+"&codigorep="+document.getElementById('codigo').value+"&nombre="+document.getElementById("nombre").value+"&subgrp=0";
  }
alert(url);
alert(qString);
  
ajax.send(qString);
}

  function 
arma_queryString(grpscolsboton) {
      
grupos "";
      
columnas "";
      
tit document.getElementById('tit0').value;
      
stit document.getElementById('tit1').value;
      
qString "tit0="+tit+"&stit="+stit+"&";
      
qString qString+"grp="+grps+"&cols="+cols;
      
grpid = new Array();
      for (
i=1i<=grpsi++) {
          
grpid "grp"+i+"_0";
          
tgrp document.getElementById(grpid).value;
          
"g"+i;
          
qString qString+"&g"+i+"="+tgrp;
      }
      for (
i=1i<=grpsi++) {
          for (
j=0j<=colsj++) {
              if (
j==0)
                 
clpid="c0_0";
              else
                 
clpid "c"+j+"_"+i;
              
tcol document.getElementById(clpid).value;
              
qString qString+"&"+clpid+"="+tcol;
              if (
j==0)
                 
selid="s0_0";
              else
                 
selid "s"+j+"_"+i;
              
tsel document.getElementById(selid).value;
              
qString qString+"&"+selid+"="+tsel;
              if (
j==0)
                 
txtid="t0_0";
              else
                 
txtid "t"+j+"_"+i;
              
ttxt document.getElementById(txtid).value;
              
qString qString+"&"+txtid+"="+ttxt;
          }
      }
      
qString qString+"&accion="+boton;
      return 
qString;
  }


function 
muestra_oculta(form) {
   if (
document.getElementById) { //se obtiene el id
      
var el document.getElementById(form); //se define la variable "el" igual a nuestro div
      
el.style.display = (el.style.display == 'none') ? 'block' 'none'//damos un atributo display:none que oculta el div
   
}
}

function 
muestra_textArea(af) {
   
idn "t"+a+"_"+f;
   
ds document.getElementById(idn);
   
ds.style.display "block";
}

function 
oculta_textArea(a) {
   
ds document.getElementById(a);
   
ds.style.display "none";


Última edición por augusto_jaramil; 06/11/2011 a las 18:04 Razón: cambio texto
  #9 (permalink)  
Antiguo 06/11/2011, 18:06
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Respuesta: Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

PARTE II

Código PHP:
String.prototype.trim = function() { return this.replace(/^s+|s+$/g""); };

function 
crearFilas() {

   var 
reporte document.getElementById("reporte");
   
reporte.innerHTML "";

   var 
grups document.getElementById("grupos").value;
   
str grups.trim();
   var 
grups parseInt(str);

   var 
cols document.getElementById("cols").value;
   
str cols.trim();
   var 
cols parseInt(str);

   if (
cols 1)
      
largo = ((152*cols+1)+(4*cols));
   else
      
largo 152*cols+1;

   
tbl document.createElement("table");
     
tbl.setAttribute("cellspacing""0");
     
tbl.setAttribute("cellpadding""0");
     
tbl.setAttribute("border""1");
     
tbl.setAttribute("background-color""white");

   
0;
   
1;

//TITULOS
   
totlar = ((largo*grups)+(1*cols))+152;
   
colsxlin = (cols*grups)+1;
   for (
i=0;i<2;i++) {
       
tr document.createElement("tr");
       
idtit="tit"+i;
       
nuevoTDt document.createElement("td");
            
nuevoTDt.setAttribute("colspan"colsxlin);
            
nuevoTDt.setAttribute("align""center");

       
input document.createElement("input");
            
input.setAttribute("type""text");
            
input.setAttribute("id"idtit);
            
input.setAttribute("name"idtit);
            if (
i==0)
               
input.setAttribute("value""Titulo Reporte");
            else
               
input.setAttribute("value""Subtitulo Reporte");
            
input.setAttribute("class""claseinput");
            
estilo "text-align:center; color:blue; width:"+totlar+"px";
            
input.setAttribute("style"estilo);
       
nuevoTDt.appendChild(input);
       
tr.appendChild(nuevoTDt);
       
tbl.appendChild(tr);
   }


   
tr document.createElement("tr");

//GRUPOS
   
nuevoTDz document.createElement("td");
       
nuevoTDz.setAttribute("class""clasetd");
   
tr.appendChild(nuevoTDz);

   for (
i=0;i<grups;i++) {
       
idnameg="grp"+k+"_0";
       
nuevoTDg document.createElement("td");
            
nuevoTDg.setAttribute("colspan"cols);
            
nuevoTDg.setAttribute("align""center");

       
input document.createElement("input");
            
input.setAttribute("type""text");
            
input.setAttribute("id"idnameg);
            
input.setAttribute("name"idnameg);
            
input.setAttribute("value""Titulo Grupo "+k);
            
input.setAttribute("class""claseinput");
            
estilo "text-align:center; color:blue; width:"+largo+"px";
            
input.setAttribute("style"estilo);
            
input.setAttribute("onChange""verificaInput('"+idnameg+"');");
       
nuevoTDg.appendChild(input);
       
tr.appendChild(nuevoTDg);
       
tbl.appendChild(tr);
       
k++;
   }

//COLUMNAS
   
tr document.createElement("tr");
   
idtit="c0_0";
   
nuevoTDx document.createElement("td");
        
nuevoTDx.setAttribute("colspan""1");
        
nuevoTDx.setAttribute("align""center");

   
input document.createElement("input");
        
input.setAttribute("type""text");
        
input.setAttribute("id"idtit);
        
input.setAttribute("name"idtit);
        
input.setAttribute("value""Id");
        
estilo "text-align:center; color:red; width:152px";
        
input.setAttribute("style"estilo);
        
input.setAttribute("class""claseinput");
        
input.setAttribute("onChange""verificaInput('"+idtit+"');");
   
nuevoTDx.appendChild(input);
   
tr.appendChild(nuevoTDx);

   
1;
   
1;
   
col_orig cols;
   
cols grups*cols;
   for (
j=0;j<cols;j++) {
       
idnamec "c"+k+"_"+g;
       
nuevoTDt document.createElement("td");
            
nuevoTDt.setAttribute("colspan""1");

       
input document.createElement("input");
            
input.setAttribute("type""text");
            
input.setAttribute("id"idnamec);
            
input.setAttribute("name"idnamec);
            
input.setAttribute("value""Titulo Columna "+k);
            
input.setAttribute("class""claseinput");
            
estilo "text-align:center; color:red; width:152px;";
            
input.setAttribute("style"estilo);
            
input.setAttribute("onChange""verificaInput('"+idnamec+"');");
       
nuevoTDt.appendChild(input);
       
tr.appendChild(nuevoTDt);
       
k+1;
       if (
k>col_orig) {
          
g+1;
          
k=1;
       }
   }
   
tbl.appendChild(tr);

//SELECTS
   
tr document.createElement("tr");
   
1;
   
1;
   for (
j=0;j<cols;j++) {
       
idnames "s"+k+"_"+g;
       if (
== 0) {
          
nuevoTDs document.createElement("td");
               
nuevoTDs.setAttribute("colspan""1");

          
nuevoSelect document.createElement("select");
               
nuevoSelect.setAttribute("id""s0_0");
               
nuevoSelect.setAttribute("name""s0_0");
               
//nuevoSelect.setAttribute("style", "width:152px; background-color:#B0E0E6;");
               
nuevoSelect.setAttribute("style""width:152px; background-color:transparent; font-size=12px; border:solid #B0E0E6;");
               
nuevoSelect.setAttribute("onChange""muestra_textArea(0,0);");

          
opt document.createElement("Option");
            
opt.setAttribute("value""I");
            
opt.innerHTML="Seleccione Filtro";
            
opt.setAttribute("selected","0");
            
opt.setAttribute("style""background-color:#00FFFF;");
          
nuevoSelect.appendChild(opt);

          
opt document.createElement("Option");
            
opt.setAttribute("style""background-color:#00FFFF;");
            
opt.setAttribute("value""Q");
            
opt.innerHTML="Query";
          
nuevoSelect.appendChild(opt);

          
nuevoTDs.appendChild(nuevoSelect);
          
tr.appendChild(nuevoTDs);
       }

       
nuevoTDs document.createElement("td");
            
nuevoTDs.setAttribute("colspan""1");

       
nuevoSelect document.createElement("select");
            
nuevoSelect.setAttribute("id"idnames);
            
nuevoSelect.setAttribute("name"idnames);
            
//nuevoSelect.setAttribute("style", "width:152px; background-color:#B0E0E6;");
               
nuevoSelect.setAttribute("style""width:152px; background-color:transparent; font-size=12px; border:solid #B0E0E6;");
            
nuevoSelect.setAttribute("onChange""muestra_textArea("+k+", "+g+");");

       
opt document.createElement("Option");
         
opt.setAttribute("value""0");
         
opt.innerHTML="Seleccione Filtro";
         
opt.setAttribute("selected","0");
         
opt.setAttribute("style""background-color:#00FFFF;");
       
nuevoSelect.appendChild(opt);

       
opt document.createElement("Option");
         
opt.setAttribute("style""background-color:#00FFFF;");
         
opt.setAttribute("value""Q");
         
opt.innerHTML="Query";
       
nuevoSelect.appendChild(opt);

       
opt document.createElement("Option");
         
opt.setAttribute("style""background-color:#00FFFF;");
         
opt.setAttribute("value""F");
         
opt.innerHTML="Formula";
       
nuevoSelect.appendChild(opt);

       
opt document.createElement("Option");
         
opt.setAttribute("style""background-color:#00FFFF;");
         
opt.setAttribute("value""C");
         
opt.innerHTML="Copiar Desde Columna";
       
nuevoSelect.appendChild(opt);

       
nuevoTDs.appendChild(nuevoSelect);
       
tr.appendChild(nuevoTDs);

       
k=k+1;
       if (
k>col_orig) {
          
g+1;
          
k=1;
       }
   }
   
tbl.appendChild(tr);

//TEXTAREA
   
tr document.createElement("tr");

   
1;
   
1;
   
cols cols+1;
   for (
j=0;j<cols;j++) {
       if (
j==0) {
          
idnamet "t0_0";
          
0;
       }
       else
          
idnamet "t"+k+"_"+g;
       
nuevoTDa document.createElement("td");
            
nuevoTDa.setAttribute("colspan""1");

       
textarea document.createElement("textarea");
            
textarea.setAttribute("id"idnamet);
            
textarea.setAttribute("name"idnamet);
            
textarea.setAttribute("rows""30");
            
textarea.setAttribute("cols""87");
            
textarea.setAttribute("onChange""verificaInput('"+idnamet+"');");
            
fun "oculta_textArea('"+idnamet+"');";
            
textarea.setAttribute("style""display : none");
            
textarea.setAttribute("onBlur"fun);
       
nuevoTDa.appendChild(textarea);
       
tr.appendChild(nuevoTDa);
       
k+1;
       if (
k>col_orig) {
          
g+1;
          
k=1;
       }
   }
   
tbl.appendChild(tr);

// BOTONES
   
tr document.createElement("tr");
   
nuevoTDb document.createElement("td");
        
nuevoTDb.setAttribute("align""center");
        
nuevoTDb.setAttribute("colspan"largo);

   
nuevoBoton document.createElement("input");
      
nuevoBoton.setAttribute("type""button");
      
nuevoBoton.setAttribute("id""graba");
      
nuevoBoton.setAttribute("accion""graba");
      
nuevoBoton.setAttribute("value""Grabar");
      
nuevoBoton.setAttribute("onClick""fDatos('reporte','grabar');");
      
nuevoBoton.setAttribute("style""background-color:#738EB5; height:18px; font-size:8pt; font-weight:bold; color:#FFFFFF; border-style:solid; border-width:1px;");
   
nuevoTDb.appendChild(nuevoBoton);
   
tr.appendChild(nuevoTDb);
   
tbl.appendChild(tr);

   
reporte.appendChild(tbl);

/*
var ss = document.getElementById('reporte').innerHTML;
ss = ss.replace(/>/g, "&gt;");
ss = ss.replace(/</g, "&lt;");
document.write(ss);
*/
   
ds document.getElementById("reporte");
   
ds.style.display "block";
   
reporte.style.display "block";
}

function 
verificaInput(par) {
//alert(document.getElementById(par).offsetWidth);
   //alert(document.getElementById(par).value);

  #10 (permalink)  
Antiguo 06/11/2011, 20:03
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Respuesta: Este Script se ejecuta 1 sola vez ajax.responseText.. Why?

Listo, solucionado.....

La función fDatos quedó así:

Código PHP:
function fDatos(contenedor,boton) {
  
ss document.getElementById("reporte");
  
ss.style.display='none';
  var 
objTbl document.getElementById(contenedor);
  var 
objErr document.getElementById("estado");

  if (
boton == "grabar")
        var 
url "genreport.php";
  if (
boton == "producir")
        var 
url "procesa_repor.php";
  if (
boton == "buscar")
        var 
url "procesa_repor.php";

  var 
qString;
  if (
boton != "grabar") {
     
cod document.getElementById("codigo").value;
     
qString "codigo="+cod+"&accion="+boton;
  }
  else {
     
grp document.getElementById("grupos").value;
     
col document.getElementById("cols").value;
     
qString arma_queryString(grp,col,boton);
     
qString qString+"&codigorep="+document.getElementById('codigo').value+"&nombre="+document.getElementById("nombre").value+"&subgrp=0";
  }

  
ajax nuevoAjax();
  
ajax.open("POST"urltrue);
  
ajax.onreadystatechange = function() {
      switch (
ajax.readyState) {
            case 
0:
                 
objTbl.innerHTML 'Error 0. No se ha abierto la comunicaci&oacute;n.';
                 break;
            case 
1:
                 
objTbl.innerHTML="<img src='./imagenes/ajax-loader.gif'>"+" Procesando su peticion, un momento por favor...";
                 break;
            case 
2:
                 
objTbl.innerHTML 'Petici&oacute;n cargada, esperando respuesta del servidor...';
                 break;
            case 
3:
                 
objTbl.innerHTML '';
                 break;
            case 
4:
                 if (
ajax.status == 200) {
                    if (
boton == "buscar") {
                       
document.getElementById("nombre").value ajax.responseText;
                       
ver document.getElementById("resporte");
                       
ver.style.display 'none';
                    }
                    else {
                       
ver document.getElementById("formulario");
                       
ver.style.display 'block';
                       
objTbl.innerHTML ajax.responseText;
                    }
                 }
                 else
                    
objTbl.innerHTML 'Error 200';
                 break;
            default:
                 break;
      }
  }
  
ajax.setRequestHeader("Content-Type""application/x-www-form-urlencoded");
  
ajax.send(qString)

Lo que hice fue cambiar switch por if's y poner todo lo que tiene que ver con armar el queryString antes de crear el objeto ajax.

Que qué tiene que ver esto? ni idea.... pero ahí me cancionó la vaina

Ahora sí no creo que el patrón me eche

Mil Gracias por todo...

Etiquetas: ajax
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:14.