Ver Mensaje Individual
  #16 (permalink)  
Antiguo 10/01/2011, 18:17
jesusjj
 
Fecha de Ingreso: noviembre-2007
Mensajes: 154
Antigüedad: 16 años, 5 meses
Puntos: 2
Respuesta: jQuery $.ajax y PHP con un CSV

Se me olvidó postear lo que hice:

Código PHP:
if(isset($_POST['pag']) && ($_POST['pag'] == 'products') && isset($_POST['clave'])) {
    
$clave $_POST['clave'];
    
$fichero $_POST['pag'];
    
    
$fileCSV '../csv/'.$fichero.'.csv';
    
$ruta_img 'content/images/products/';
    
    
//echo $fileCSV;
    
    
$csv fopen($fileCSV"r") or die ("Error al abrir archivo CSV");
    
    
    echo 
"<table id='tb_products'>";
           
    while((
$data fgetcsv($csv1000";")) != FALSE ) {
    
        if(
$data['1'] == $clave) {
            echo 
"<tr>";
            echo 
"<td class='td_img'><img src='$ruta_img$data[4]' title='".utf8_encode($data[5])."' alt='".utf8_encode($data[5])."' /></td>"// impresión de imagens
            
echo "<td class='td_desc'><h3>".utf8_encode($data[2])."</h3>".utf8_encode($data[3])."</td>"// impresión en dos líneas de producto yu descripción
            
echo "</tr>";            
        }
    }
    
    echo 
"</table>";

Código Javascript:
Ver original
  1. // Ventana Modal      
  2.     //When you click on a link with class of poplight and the href starts with a #
  3.     $('a.poplight[href^=#]').click(function() {
  4.         var popID = $(this).attr('rel'); //Get Popup Name
  5.         var popURL = $(this).attr('href'); //Get Popup href to define size
  6.    
  7.         //Pull Query & Variables from href URL
  8.         var query= popURL.split('?');
  9.         var dim= query[1].split('&');
  10.         var popWidth = dim[0].split('=')[1]; //Gets the first query string value
  11.        
  12.         // Modifico script para asignar dinámicamente el id al div
  13.         $(".popup-block").attr('id', popID);
  14.        
  15.         // Envío por ajax el atributo id para indicar el contenido a cargar
  16.         //$.post('index.php', {pag:'products', clave: popID},
  17.         $.post('content/includes/php/products.php', {pag:'products', clave: popID},
  18.             function(data) {
  19.                  console.log(data);
  20.                
  21.                 //Fade in the Popup and add close button
  22.                 //Generamos el listado de productos
  23.                 $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="content/images/theme/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
  24.                 $('#' + popID).fadeIn()
  25.                   .css({ 'width': Number( popWidth ) })
  26.                   .html(data).prepend('<a href="#" class="close"><img src="content/images/theme/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
  27.                    
  28.                 //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
  29.                 var popMargTop = ($('#' + popID).height() + 80) / 2;
  30.                 var popMargLeft = ($('#' + popID).width() + 80) / 2;
  31.            
  32.                 //Apply Margin to Popup
  33.                 $('#' + popID).css({
  34.                     'margin-top' : -popMargTop,
  35.                     'margin-left' : -popMargLeft
  36.                 });
  37.            
  38.                 //Fade in Background
  39.                 $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
  40.                 //$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies
  41.                
  42.                 // modifico el filtro alpha por el fade del diaplay
  43.                 $('#fade').css({'display' : 'block'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies          
  44.         });
  45.    
  46.         return false;
  47.     });
  48.  
  49.     //Close Popups and Fade Layer
  50.     $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
  51.         $('#fade , .popup-block').fadeOut(function() {
  52.             $('#fade, a.close').remove();  //fade them both out
  53.         });
  54.         return false;
  55.     });
  56.    
  57. });

Código HTML:
Ver original
  1. <a href='#?w=870' rel='prod1' class='poplight'></a>

Saludos