Comunidad de diseño web y desarrollo en internet online

Como ejecuto mi script (si ya se que suena tonto)

Citar            
MensajeEscrito el 30 Sep 2008 03:22 pm
Leyendo un manual vi un codigo que recoge los datos de un formulario los envia via POST y muestra la pagina resultante en un DIV incluido en la primera pagina, has ta ahi mostro se lo que y es precisamente lo que quiero el problema es donde, en que parte del codigo HTML le digo que ejecute el script aqui envio los respectivos codigos

Código Javascript :

<script language="javascript" type="text/javascript">
var READY_STATE_COMPLETE=4;
var peticion_http = null;
function inicializa_xhr() {
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function crea_query_string() {
var cl = document.getElementById("clave");
var cr = document.getElementById("criterio_str");
return "clave=" + encodeURIComponent(cl.value) +
"&criterio_str=" + encodeURIComponent(cr.value) +
"&nocache=" + Math.random();
}
function busca() {
peticion_http = inicializa_xhr();
if(peticion_http) {
peticion_http.onreadystatechange = procesaRespuesta;
peticion_http.open("POST", "/usuario_ver_omega.php", true);
peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var query_string = crea_query_string();
peticion_http.send(query_string);
}
}
function procesaRespuesta() {
if(peticion_http.readyState == READY_STATE_COMPLETE) {
if(peticion_http.status == 200) {
document.getElementById("resultados").innerHTML = peticion_http.responseText;
}
}
}
</script>

Código HTML :

<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
  <td>
    <table width="100%" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td class="left">&nbsp;</td>
        <td width="15" class="center"><img src="imagenes/bullet_title.gif"></td>
        <td align="left" class="center"><span class="Estilo3">Modulo
            de Usuarios.</span></td>
        <td class="right">&nbsp;</td>
      </tr>
    </table>
  </td>
  </tr>
<tr>
  <td align="center" style="padding-top:10px">
    <form action="javascript:busca();" method="post" name="buscador" id="buscador" style="border:none">
      <input type="text" name="clave" id="clave" value="Ingrese texto a buscar" onFocus="if(this.value=='Ingrese texto a buscar')this.value='';" style="width:30%; margin-right:20px">
      <input type="submit" name="submit" id="submit" value="Buscar">
                <br>
<br/>
                  <label>Seleccione un criterio de Busqueda :<br/>
                  <input name="criterio_str" type="radio" value="Nombres" id="GrupoOpciones1_0" checked>
                 Nombres</label>
                  <label>
                    <input name="criterio_str" type="radio" value="Apellidos" id="GrupoOpciones1_1">
                    Apellidos</label>
                  <label>
                    <input name="criterio_str" type="radio" value="Cargo" id="GrupoOpciones1_2">
                    Cargo</label>
                  <label>
                    <input name="criterio_str" type="radio" value="Area" id="GrupoOpciones1_3">
                    Area</label>
                  <label>
                    <input name="criterio_str" type="radio" value="Nacionalidad" id="GrupoOpciones1_4">
                    Nacionalidad</label>
    </form>
    </td>
</tr>
<tr>
  <td>
  <div id="resultados">
  </div>
</body>
</html>


Esa es la primera pagina la del formulario y esta es la que muestra

Código PHP :

<?php
require_once('Connections/conexion.php');
session_start();
if (isset($_POST[criterio_str]) && isset($_POST[clave])){
$criterio = $_POST[criterio_str];
$clave = $_POST[clave];
echo "Criterio de busqueda : $criterio<br/>";echo "Clave de busqueda : $clave<br/>";
switch ($criterio) {
   case "Nombres" :
   $busqueda = "pre_nombre LIKE '%".$clave."%' OR mas_nombre LIKE '%".$clave."%'";
   break;
   case "Apellidos" :
   $busqueda = "ap_paterno LIKE '%".$clave."%' OR ap_materno LIKE '%".$clave."%'";
   break;
   case "Cargo":
   $busqueda = "cargo_ingreso LIKE '%".$clave."%'";
   break;
   case "Area":
   $busqueda = "area_ LIKE '%".$clave."%'";
   break;
   case "Nacionalidad":
   $busqueda = "nacionalidad LIKE '%".$clave."%'";
   break;
   default :
   $busqueda = "ap_paterno LIKE '%".$clave."%' OR ap_materno LIKE '%".$clave."%' OR ap_paterno LIKE '%".$clave."%' OR ap_materno LIKE '%".$clave."%' OR cargo_ingreso LIKE '%".$clave."%' OR area_ LIKE '%".$clave."%' OR nacionalidad LIKE '%".$clave."%'";
   break;
}

$query_Usuarios = "SELECT * FROM usuarios_ WHERE $busqueda";
$Usuarios = mysql_query($query_Usuarios) or die(mysql_error());
$row_Usuarios = mysql_fetch_assoc($Usuarios);
$totalRows_Usuarios = mysql_num_rows($Usuarios);

}
?>
<link href="estilos.css" rel="stylesheet" type="text/css">
<body>
  <? if (isset($criterio) && isset($clave)) { ?>
  <table width='100%' border='0' align='center' cellpadding='0' cellspacing='10'>
<tr>
  <td colspan="2">Resultados de Buscar <strong>"<?php echo $clave; ?>"</strong> por <strong><?php echo $criterio."</strong> : <strong>".$totalRows_Usuarios."</strong> registros coincidientes";?></strong></td>
</tr>
<?php if ($totalRows_Usuarios > 0) {?>
<tr>
  <td colspan='2'>
  <table width="95%" border="0" align="center" cellpadding="0" cellspacing="5">
  <tr>
        <td><strong>APELLIDOS,
            Nombres</strong></td>
        <td><strong>Area</strong></td>
        <td><strong>Cargo</strong></td>
        <td><strong>Nacionalidad</strong></td>
        <td align="center"><strong>Ver</strong></td>
      </tr>
      <?php
 do {  
   ?>
      
      <tr>
      <td>
     <?php echo strtoupper($row_Usuarios['ap_paterno']." ".$row_Usuarios['ap_materno']).", ".ucwords(strtolower($row_Usuarios['pre_nombre']." ".$row_Usuarios['mas_nombre'])); ?>      </td>
      <td><?php echo $row_Usuarios['area_'];?></td>
      <td><?php echo $row_Usuarios['cargo_ingreso'];?></td>
      <td><?php echo $row_Usuarios['nacionalidad'];?></td>
      <td width="75px" align="center">
      <a href='javascript:showing("destino","ver_user.php?user=<? echo $row_Usuarios['Id'] ?>")'>Ver Ficha</a></td>
      </tr>
      <?php
} while ($row_Usuarios = mysql_fetch_assoc($Usuarios));
  $rows = mysql_num_rows($Usuarios);
  if($rows > 0) {
      mysql_data_seek($Usuarios, 0);
     $row_Usuarios = mysql_fetch_assoc($Usuarios);
  }
?>
  </table>
  </td>
</tr>
<?php } else {?>
<tr>
<td colspan="2">
<strong>La busqueda no reporta resultados</strong></td>
</tr>
<?php } ?>
</table>
  <? }; ?>
</body>
</html>
<?php
if (isset($_POST[criterio_str]) && isset($_POST[$clave])){
   mysql_free_result($Usuarios);
   };
?>


Existe algun error en mi codigo? pq cuando le doy al boton BUSCAR (submit) la pagina no hace nada de nada.

Por NeoCesar

Claber

1415 de clabLevel

14 tutoriales

Genero:Masculino  

Algun lugar dentro de la Matrix (Lima - Perú)

firefox
Citar            
MensajeEscrito el 30 Sep 2008 09:29 pm
Ya logre que corra el script :p weno ahora el problema es otro esta pagina la que se ve arriba se carga via AJAx dentro de un DIV de otra pagina, entonces mientras la pagina que postee antes corre sola sin estar dentro de un DIV todo funciona de las mil maravillas, pero cuando la llamo desde la otra pagina para que se incruste en el DIV mecionado, deja de funcionar el script y haga lo que haga no ejecuta la consulta se queda parado y no hace nada de nada, porque podra ser la pagina madre se llama main.php, el DIV se llama "Destino", el archivo que se incluye en el DIV se llama usuario_ver_alpha.php, este a su vez contiene un DIV nombrado "resultados" dentro del cual se muestran los resultados xD arrojados por usuario_ver_omega.php, no se si estrara claro, he intentado poner el script dentro del header de main.php y nada, dentro del body de usuario_ver_alpha.php y nada tampoco, obvio no lo puedo poner en el head de usuario_ver_alpha.php porque esta pagina se anida dentro de main y su head nunca se ve (si estoy equivocado pls corrijanme) .

Alguien quem e ayude pls

Por NeoCesar

Claber

1415 de clabLevel

14 tutoriales

Genero:Masculino  

Algun lugar dentro de la Matrix (Lima - Perú)

firefox
Citar            
MensajeEscrito el 30 Sep 2008 09:33 pm
A la solucion al problema de antes es en el boton del form
dice

Código HTML :

<form action="javascript:busca();" method="post" name="buscador" id="buscador" style="border:none"> 
      <input type="text" name="clave" id="clave" value="Ingrese texto a buscar" onFocus="if(this.value=='Ingrese texto a buscar')this.value='';" style="width:30%; margin-right:20px"> 
      <input type="submit" name="submit" id="submit" value="Buscar"> 


debe decir

Código HTML :

<form style="border:none"> 
      <input type="text" name="clave" id="clave" value="Ingrese texto a buscar" onFocus="if(this.value=='Ingrese texto a buscar')this.value='';" style="width:30%; margin-right:20px"> 
      <input type="button" name="buscar" id="buscar" value="Buscar"> 


tambien hay que añadir lo siguiente al script

Código Javascript :

window.onload = function () {
document.etElementById("buscar").onclick = busca();
}

Por NeoCesar

Claber

1415 de clabLevel

14 tutoriales

Genero:Masculino  

Algun lugar dentro de la Matrix (Lima - Perú)

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.