Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/09/2015, 15:51
pips
 
Fecha de Ingreso: octubre-2011
Mensajes: 104
Antigüedad: 15 años
Puntos: 1
enviar variables, php, ajax, jquery, mysql

hola, estoy intentado enviar la variable foo al archivo data para que imprima los resultados que vienen de las categorias y no hay manera, he intentado de todo y recurro aquí cdo ya no se que hacer..
Los archivos q utilizo son:

archivo helper.php (funciones)
Código PHP:
class helper{
public function 
categorias(){
@
$foo='pantalones_cortos';
    
$html = ""; 
    
$html .= '<a href="data.php?foo='.$foo.'"  onclick="advar('.$foo.')">'.$foo.'</a>'; 
    return 
$html;        
    }

public function 
get_resultados($offset = 0, $limit = 36, $dir = true, $foo = true){    
        try {
            
$this->dbh = new Conexion();                
            
$sql = "SELECT imagen,precio FROM pantalones ";            
            if(isset(
$_REQUEST["dir"]) && ($_REQUEST["dir"] == "2")){                    
                
$dir = $_SESSION["dir"]='DESC';
            }else{
                
$dir = $_SESSION["dir"]='ASC';
                }            
[
COLOR="Yellow"]    @$foo=$_GET["foo"];    [/COLOR]                                
    
$sql = $sql. " WHERE pantalones.codigo = ? ";
    
$sql = $sql. " ORDER BY pantalones.precio $dir ";
            if(
$offset == 0){
                
$_SESSION["actual"] = 1;
            }else{
                
$_SESSION["actual"] = $offset/$limit;
            }                    
                
$_SESSION["limit"] = $limit;
    
$sql = $sql. " LIMIT ?,? ";
    
$query = $this->dbh->prepare($sql);
    
$query->bindValue(1, $foo, PDO::PARAM_STR);                    
        
$query->bindValue(2, (int) $offset, PDO::PARAM_INT); 
        
$query->bindValue(3, (int) $limit, PDO::PARAM_INT);             
        
$query->execute(); 
            if(
$query->rowCount() > 0)
            {                 
                 return 
$query->fetchAll(PDO::FETCH_ASSOC);    
            }            
        }catch(
PDOException $e){            
            print 
"Error!: " . $e->getMessage();            
        }}
} 
archivo datacategorias.php
Código PHP:
<?php
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 
{ 
require(
"../../lib/util/helper.php");
require(
"../../configuration.php");
    
$variables = new Helper();
    
$categorias = $variables->categorias();
        echo 
$categorias;
}else{   
    echo 
"Lo sentimos ha ocurrido un error";
}
archivo datagrid.php donde se cocinan los resultados
Código PHP:
<?php
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 
{
      require(
"../../lib/util/helper.php");
      require(
"../../configuration.php");    

    
$variables = new Helper();
        @
$offset = !isset($_GET["offset"]) || $_GET["offset"] == "undefined" ? 0 : $_GET["offset"];
        @
$limit = !isset($_GET["limit"]) || $_GET["limit"] == "undefined" ? 36 : $_GET["limit"];
        @
$dir = !isset($_GET["dir"]) || $_GET["dir"] == "undefined" ? 'ASC' : $_GET["dir"];
        @
$foo = !isset($_GET["foo"]) || $_GET["foo"] == "undefined" ? 'pantalones_cortos' : $_GET["foo"];    
        
    
$orderby = $variables->crea_orderby();   
    
$productos = $variables->get_resultados($offset,$limit,$dir,$foo); 
   
$paginacion = $variables->crea_paginacion();
    echo 
json_encode(array(
                    
"prdcts" => $productos,
                    
"pgncn" => $paginacion,
                    
"rdrby" => $orderby
                    
));
}else{
    echo 
"Esta página no existe";}
el archivo ajax.js
Código PHP:
$(document).on("ready",function(){
    $.
get('lib/dinamic/datacategorias.php',function(data){
        $(
'.categorias').html(data);
        });});

function 
advar(offset, limit, dir, foo){
    $.
get("lib/dinamic/datagrid.php/?offset=" + offset + "&limit=" + limit + "&dir=" + dir + '&foo=' + foo, function(data){
      
// console.log(data)
           //alert(foo);
        
if(data){
            
$html = "";
                
json = JSON.parse(data);
                for(
datos in json.prdcts){
                    
$html += "<div class='row'>";
                        
$html += "<img class='imagen' src=" + json.prdcts[datos].imagen + ">";
                        
$html +=  + json.prdcts[datos].precio ;                         
                    
$html += "</div>";
                }
            $(
".resultados").html("");
            $(
".resultados").html($html);        
            $(
".orderby").html("");
            $(
".orderby").html(json.rdrby);    
            $(
".paginacion").html("");
            $(
".paginacion").html(json.pgncn);
 }});}

$(
window).on("load", function(){
    
advar();
}); 
Y los archivos donde se imprimen
archivo categorias.php
Código PHP:
<!DOCTYPE html>
<
html lang="es">
<
head>
    <
meta charset="utf-8" />
    <
title></title>
<
script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
 <script type="text/javascript" src="js/ajax.js"></script>
</head>
<body>
<div class="categorias"></div> <br>
</body>
</html> 
archivo data.php donde se muestran los resultados
Código PHP:
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="utf-8" />
    <title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
 <script type="text/javascript" src="js/ajax.js"></script>
    <?php 
    
@$foo=$_GET["foo"];    
    
//var_dump($foo); 
    
?>
</head>
<body>
<div class="content">
    <div class="row">         
             <div class="num"></div>
                <div class="paginacion"></div>
        <div class="orderby"></div>
                <div class="resultados"></div>
    </div>
</div>
</body>
</html>

Saludos y gracias