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

Guardar variable

Estas en el tema de Guardar variable en el foro de Frameworks JS en Foros del Web. Hola a todos.. bueno me he animado a postear mis dudas, despues de mucho estar mirando, soy nuevo en esto del ajax y mi problema ...
  #1 (permalink)  
Antiguo 10/04/2007, 21:16
 
Fecha de Ingreso: agosto-2005
Mensajes: 2
Antigüedad: 18 años, 8 meses
Puntos: 0
Guardar variable

Hola a todos.. bueno me he animado a postear mis dudas, despues de mucho estar mirando, soy nuevo en esto del ajax y mi problema creo q es sencillo..

Tengo una pagina :

Código PHP:
<title>Preloader en AJAX</title>
<
script language="javascript" type="text/javascript">

var 
UltFec;

function 
objetoAjax(){
    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 
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 
Cargar(url){


var 
cod=document.getElementById("cod").value;
var 
contenido,nombre;
contenido document.getElementById('contenido');
//pepe = document.getElementById('pepe');
ajax=NuevoAjax();
ajax.open("GEST"url,true);
ajax.setRequestHeader("Content-Type""application/x-www-form-urlencoded");
ajax.send("v="+cod);

ajax.onreadystatechange=function(){
    if(
ajax.readyState==1){
        
preloader.innerHTML "Cargando...";
        
preloader.style.background "url('bariloche.jpg') no-repeat";
    }else if(
ajax.readyState==4){
        if(
ajax.status==200){
            
contenido.innerHTML ajax.responseText;
            
preloader.innerHTML "Cargado.";
            
// imagen se carga dentro de cargando
            
preloader.style.background "url('bariloche.jpg') no-repeat";
        }else if(
ajax.status==404){
            
preloader.innerHTML "La página no existe";
        }else{
            
preloader.innerHTML "Error:".ajax.status;
        }
    }
}


}
    
</script>
</head>
<body>


<form action ='basededatos2.php' method='POST' onClick=javascript:Cargar('basededatos2.php')>
                 Nombre: <INPUT id="cod" TYPE="text" NAME="nombre" value="123"><br>
                 <input type='submit' value='Buscar'>
                 </form>

<script>document.write(valorx) </script>
<div id="contenido"></div> 
Donde le pregunto por un nombre, mi problema es de q no puedo extraer lo q escribe en el text, y mandarlo a basededatos2.php

Código PHP:
<?php session_start(); ?>
<html>
<head><title>mysql</title></head>
<body>
<?php 

    $fnom
$_POST['v'];
    
$fnom2$_POST['nombre'];
    echo 
$fnom." nada ".$fnom2;

include(
"servidor.php");//Abrimos conexion
$conexion=mysql_connect(HOST,USUARIO,PASS) or die ("Hay un error en la conexion de la base de datos(host, name o pass)");

//Seleccionamos BD
$bd =mysql_select_db(BASE,$conexion) or die ("No existe base de datos");

//Hacemos consulta
$consulta"SELECT * FROM proyecto WHERE nombre='$fnom'";
$resultado=mysql_query($consulta) or die ("No hay tablas");
echo 
$fnom."dsdsdsdsd";
echo 
mysql_num_rows($resultado);

echo 
"<table border='1' >";
while(
$fila =mysql_fetch_array($resultado,MYSQL_ASSOC)){
    
extract($fila);
    echo 
"<tr><td>".$id_proyecto."</td>";
    echo 
"<td>".$NOMBRE."</td>";
    echo 
"<td>".$APELLIDOS."</td>";
    echo 
"<td>".$EDAD."</td></tr>";
}
echo
"</table>";





//Cerramos conexion
mysql_close($conexion);

?>
Nose si alguien me pueda echar una manita y decirme como hacerlo ... muchas gracias..

Resumiendo: quiero q cuando escriba un nombre en el text, y le de enviar, lo mande a la otra pagina de php, y ahi pueda hacer la bsuqueda, y en la pagina donde esta el text (abajo), mostrar el resultado.
  #2 (permalink)  
Antiguo 10/04/2007, 21:46
 
Fecha de Ingreso: agosto-2005
Mensajes: 2
Antigüedad: 18 años, 8 meses
Puntos: 0
Re: Guardar variable

Ya lo he resuelto ")... pongo la solucion ..

Ejemplo.php

Código PHP:
<html>
<
head>
<
title>AjaxEjemplo 2 Envío de datos por el método GET</title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</
head>
<
script language="javascript">
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 
cargarContenido(){
var 
t1contenido;
contenido document.getElementById('contenido');
t1 document.getElementById('texto1').value;
ajax=nuevoAjax();
ajax.open("GET""basededatos2.php?t1="+t1,true);
ajax.onreadystatechange=function() {
if (
ajax.readyState==4) {
contenido.innerHTML ajax.responseText
}
}
ajax.send(null)
}

</script>
<style type="text/css">
#contenedor{
border: 1px solid #f00;
padding: 10px;
margin: 14px;
}
</style>
<body>
<form onSubmit="cargarContenido(); return false">
<div><input type="text" id="texto1" value="valor1" /></div>
<div><input type="submit" value="Buscar" onPress="cargarContenido()" /></div>
</form>

<div id="contenido"></div>

</body>
</html> 
Y el q jalamos
basededatos2.php
Código PHP:
<?

include("servidor.php");//Abrimos conexion
$fnom=$_GET['t1'];
$conexion=mysql_connect(HOST,USUARIO,PASS) or die ("Hay un error en la conexion de la base de datos(host, name o pass)");

//Seleccionamos BD
$bd =mysql_select_db(BASE,$conexion) or die ("No existe base de datos");

//Hacemos consulta
$consulta"SELECT * FROM proyecto WHERE nombre='$fnom'";
$resultado=mysql_query($consulta) or die ("No hay tablas");

//echo mysql_num_rows($resultado);

echo "<table border='1' >";
while(
$fila =mysql_fetch_array($resultado,MYSQL_ASSOC)){
    
extract($fila);
    echo 
"<tr><td>".$id_proyecto."</td>";
    echo 
"<td>".$NOMBRE."</td>";
    echo 
"<td>".$APELLIDOS."</td>";
    echo 
"<td>".$EDAD."</td></tr>";
}
echo
"</table>";

//Cerramos conexion
mysql_close($conexion);
?>
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:48.