Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/08/2008, 01:41
Avatar de Shagraarath
Shagraarath
 
Fecha de Ingreso: agosto-2008
Mensajes: 151
Antigüedad: 15 años, 9 meses
Puntos: 1
Exclamación [Ayuda] Enviar datos por Ajax a un PHP y que me retorne la info

Buenas peña ^^

Estoy con un proyecto en el trabajo y hay algo que no se
muy bien como hacer. T

Tengo un codigo con un reproductor que coje la
ruta del video por una variable en PHP que busca en la BBDD MySQL.

El codigo es este:

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>Documento sin t&iacute;tulo</title>
<style type="text/css">
/* player and playlist go side by side */
#player, div.playlist {
    float:left;        
    margin-right:20px; 
}

div.playlist {
    width:150px;        
}

/* player dimensions */
#player, #player img {
    display:block;                
    width:300px;
    height:240px;
    border:0px;        
}

/* play button on top of splash image */
div.play {
    background:url(../img/btn/play.png) no-repeat;
    width:50px;
    height:50px;
    position:relative;
    top:-140px;
    left:125px;    
    opacity:0.9;
    margin-bottom:-50px;
}

div.play:hover {
    opacity:1.0;        
}


/* single playlist item */
div.items a {
    background:url(../tools/img/block.jpg) no-repeat;
    width:150px;
    height:68px;
    display:block;
    text-decoration:none;
}

div.items p {
    font-size:11px;
    width:130px;
    padding:8px 0 0 12px;
    margin:0px;        
}

div.items p.time {
    padding-top:0px;
    color:#777;
    margin-top:5px;


/* item stages: normal, hover, playing, paused */
div.items a:hover {
    background-position:0 -68px;    
}

div.items a.playing, div.items a.paused {
    color:#000;    
}

div.items a.playing {
    background-position:0 -136px;        
}

div.items a.paused {
    background-position:0 -68px;    
}


/* small navigational dots */
div.navi {
    width:60px;    
    float:left;
    margin:10px 0 0 50px;
}

div.navi span {
    width:8px;
    height:8px;
    float:left;
    margin:3px;
    background:url(../tools/img/dots.png) 0 0 no-repeat;        
    cursor:pointer;
}

div.navi span:hover {
    background-position:0 -8px;        
}

div.navi span.active {
    background-position:0 -16px;        
}
</style>
<?
$caida 
="caida.mov"
?>
<script>
// setup scrollable playlist when page is scriptable  
$(document).ready(function() {             
 
    // setup Flowplayer playlist from <div.items/> 
    $("div.items").playlist( 
     
        // flash parameters 
        "FlowPlayerLP.swf", 
         
        // flowplayer configuration 
        {initialScale:'scale'},  
         
        // playlist configuration 
        {loop:true} 
    ); 
     
    // make playlist scrollable    
    $("div.playlist").scrollable({size:3});     
 
});
</script>
</head>


<body>
<? 
    $link 
mysql_connect("localhost""root"); //codigo de consulta de base de datos
      
$connect=mysql_select_db("deporte",$link);
    
$querymysql_query("SELECT Ruta FROM videos WHERE ID = 59");
    
$row=mysql_fetch_array($query);
   if(
mysql_num_rows($query)!=0){
     echo 
$row["Ruta"];    
     }
?>

<div class="playlist"> 
 
    <!-- playlist items --> 
    <div class="items"> 
     
        <a href="caidas.flv" target="FlowPlayer"> <!-- aqui querria poner una variable con un valor a pasar por AJAXy que se me ejecutara una funcion AJAX -->
            <p>Video1</p>         
            <p class="time">1:32 sec</p> 
        </a>     
         
        <a href="caida.mov" target="FlowPlayer" >  <!-- aqui querria poner otra variable con un valor a pasar por AJAXy que se me ejecutara una funcion AJAX -->
            <p>Video 2</p>         
            <p class="time">1:32 sec</p> 
        </a>             
         
        <!-- ... rest of the items goes here ... --> 
         
    </div> 
     
    <!-- navigator is auto generated inside this tag --> 
    <div class="navi">
<object type="application/x-shockwave-flash" name="FlowPlayer" width="400" height="300" id="FlowPlayer" data="FlowPlayerLP.swf" style="margin-left:300; position:absolute; left: 398px; top: 8px; allowFullScreen:true;">
  <param name="scale" value="noScale"/>
  <param name="wmode" value="transparent"/>
  <param name="allowFullScreen" value="true" />
  <param name="quality" value="high"/>
  <param name="flashvars" value="config={
    showPlayList: true,
    showPlayListButtons: true,
    loop: false,sa
    autoPlay:false,
    initialScale: 'fit',
    useNativeFullScreen: true,
    fullScreenScriptURL:'fullscreen.js',
    playList: [
      { url:'<? echo $row["Ruta"?>',
        name:' Caidas tontas ROFL' },
    ]
  }"/>
</object>
    </div> 
     
</div>
</body>
</html>
Lo que necesito es que al apretar los links ( los marcados por comentario )se ejecute alguna
funcion por AJAX que envie una variable ( cada una distinta por link "Row=7", "Row=8") a una
pagina PHP ( el codigo de la PHP ya la tengo ) y que me retorne el dato que necesito.

Estoy muy perdido en AJAX, si alguien pudiera ayudarme con ejemplos en mi codigo lo veria mas
claro todo y sabria como hacerlo mucho mejor.

[ OPCION EXTRA ]


Esta opcion la pongo por si fuera posible y si fuera mas facil que la primera.

Seria posible que la consulta a la BBDD que tengo al principio del body se ejecutara como funcion
AJAX y buscara en la BBDD y me retornara el valor sin refrescar la pagina?

Todo esto enviando una variable desde los links a la funcion quedando en vez de asi:


Código PHP:
    $querymysql_query("SELECT Ruta FROM videos WHERE ID = 59"); 
asi:

Código PHP:
    $querymysql_query("SELECT Ruta FROM videos WHERE ID = VARIABLE ENVIADA POR LINK"); 

Última edición por Shagraarath; 28/08/2008 a las 02:03