Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Mostrar mensaje mediante innerHTML

Estas en el tema de Mostrar mensaje mediante innerHTML en el foro de Frameworks JS en Foros del Web. Buenos dias compañeros de Foros de Web, estoy aprendiendo ajax y se me ha presentado la siguiente duda: Tengo un div donde se van a ...
  #1 (permalink)  
Antiguo 27/09/2011, 06:47
 
Fecha de Ingreso: enero-2011
Ubicación: Maracaibo
Mensajes: 179
Antigüedad: 13 años, 3 meses
Puntos: 2
Mostrar mensaje mediante innerHTML

Buenos dias compañeros de Foros de Web, estoy aprendiendo ajax y se me ha presentado la siguiente duda:

Tengo un div donde se van a mostrar los resultados al hacer la peticion a la base de datos y otro div donde me mostrara que se estan cargando los datos, que desaparece al encontrar los datos.

Lo que quiero lograr es que cuando la peticion a la base de datos sea vacia, es decir q no consiga datos, me muestre un mensaje que diga que la consulta es vacia. Cuando no hay datos me muestra la cabecera de la tabla sin datos, quisiera cambiar eso por dicho mensaje, he cambiado los innerHTML, he colocado condiciones y no he podido resolver.

Les dejo aqui el codigo donde esta el AJAX

Código PHP:
<?php
 
include("conex.php");
 
set_time_limit(0);

 
 
$sql="select mov_fecha from dpmovinv group by mov_fecha order by mov_fecha desc"
 
$result=mysql_query($sql);
 
$result2=mysql_query($sql);
 
 
$doc "select distinct(if((doc_tipdoc)='CTZ','PROFORMA','FACTURACION')) AS doc from dpdoccli";
 
$docs mysql_query($doc);
 
 
$conv "select cen_codigo,cen_descri from dpcencos order by cen_descri";
 
$rest mysql_query($conv);
?>
<!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=iso-8859-1" />
<link rel="Shortcut Icon" href="ico.ico" type="imagenes/ico" />
<meta http-equiv="" content=" URL="index.php" charset=latin2"  />
<link rel=stylesheet href="style.css" type="text/css">
<title>CONSULTA MERCAL HOGAR</title>
<style type="text/css">
<!--
.Estilo1 {
    font-size: 36px;
    font-weight: bold;
}
.Estilo2 {
    color: #0000FF;
    font-size: 24px;
}
-->
</style>

<script type="text/javascript">
function showUser(fch_dsd,fch_hst,conv,str)
{
if (fch_dsd=="0" || fch_hst=="0" || conv=="0" || str=="0")
  {
  document.getElementById("txtHint").innerHTML="Debe seleccionar todos Criterios de Busqueda";
  
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==1){
    document.getElementById("preloader").innerHTML = "Cargando...";
    //modificamos el estilo de la div, mostrando una imagen de fondo
   //document.getElementById("preloader").style.background = "url('loading.gif') no-repeat"; 
  }
  else if (xmlhttp.readyState==4)
    {
    if (xmlhttp.status==200){
      document.getElementById("preloader").innerHTML = "";
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
      //document.getElementById("preloader").innerHTML = "No se encontraron Datos para esta Empresa";
      //document.getElementById("preloader").style.background = "";
      }
      
    }
  }
xmlhttp.open("GET","resultado.php?q="+fch_dsd+"&a="+fch_hst+"&b="+conv+"&c="+str,true);
xmlhttp.send();
}
</script>

</head>

<body>
 
<table width="1006" border="0" align="center">
  <tr>
    <td width="1000"><div align="center"><img src="imagenes/superior.png" alt="ImagenSuperior" width="958" height="56" /></div></td>
  </tr>
  <tr>
    <td><table width="200" border="0" align="right">
      <tr>
        <td>
            
            <div align="center">
              <?php 
                
echo date('d-m-Y'); 
              
?>        
              </div></td>
      </tr>
   
   <form id="form1" name="form1" method="post" action="">
    
    </table>
      <p>&nbsp;</p>
      <p align="center" class="Estilo1">REPORTES  </p>
      <div align="center">
        <table width="581" border="0" align="left">
          <tr>
            <th width="138" scope="row"><div align="right">Fecha Desde: </div></th>
            <td width="103">
            <select name="fch_dsd" id="fch_dsd">
            <option value="0">--- Seleccione ---</option>
               <?        while($array=mysql_fetch_array($result)) {?>
                        <option value="<?=$array['mov_fecha']; ?>"><?=$array['mov_fecha']; ?></option>
                <? ?></select>
            </td>
            <td width="11">&nbsp;</td>
            <td width="114"><div align="right"><strong>Convenio:</strong></div></td>
            <td width="193">
                
            <select name="convenio" id="convenio">
            <option value="0">--- Seleccione ---</option>
                <option value="Todos">Todos</option>
               <?        while($convenio=mysql_fetch_array($rest)) {?>
                        <option value="<?=$convenio['cen_codigo']; ?>"><?=$convenio['cen_descri']; ?></option>
                <? ?>
               </select>    
            </td>
          </tr>
          <tr>
            <th scope="row"><div align="right">Fecha Hasta: </div></th>
            <td>
             <select name="fch_hst" id="fch_hst">
            <option value="0">--- Seleccione ---</option>
               <?        while($array=mysql_fetch_array($result2)) {?>
                        <option value="<?=$array['mov_fecha']; ?>"><?=$array['mov_fecha']; ?></option>
                <? ?></select>
            </td>
            <td>&nbsp;</td>
            <td><div align="right"><strong>Documento:</strong></div></td>
            <td>
               <select name="documento" id="documento">
            <option value="0">--- Seleccione ---</option>
               <?        while($documento=mysql_fetch_array($docs)) {?>
                        <option value="<?=$documento['doc']; ?>"><?=$documento['doc']; ?></option>
                <? ?></select>    
             </td>
          </tr>
        </table>
        <table width="164" border="0" bordercolor="#000000">
          <tr>
            <th width="158" height="43" scope="row"><span class="Estilo1"><span class="Estilo2"><img src="imagenes/images.jpg" width="81" height="92" /></span></span>
              
                  <input name="buscar" type="button" onclick="showUser(fch_dsd.value,fch_hst.value,convenio.value,documento.value)" value="Buscar" />
                </label>
              </form>
            
            </th>
          </tr>
              </table>
      </div>
      <table width="1014" border="2" bordercolor="#000000" bgcolor="#FFFFFF">
        <tr>
          <th width="1002" bordercolor="#000000" scope="row">
          <div id="txtHint" class="centrado"><b>Resultado</b></div>
          <div id="preloader" class="centrado" style="width:auto; height:auto" ></div>
          </th>
          
          
        </tr>
      </table>
      <table width="292" border="2" align="right" bordercolor="#000000">
        <tr>
          <th width="286" scope="row"><img src="imagenes/logo datapronet II.png" width="192" height="37" /></th>
        </tr>
      </table>    
      </td>
  </tr>
</table>
</body>
</html>
En este codigo esta el AJAX y los div donde se mostraran los datos

Espero me haya explicado y puedan ayudarme

Saludos

Etiquetas: ajax, php+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 11:40.