Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/05/2011, 20:35
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Cargar varios Div con una sola peticion

Sí es posible. Solo tienes que crear en PHP lo que quieras y cuando hagas la petición lo añades con innerHTML. Algo así
Código PHP:
<?php
if(!empty($_POST['foo'])){
    
$n 1;
    foreach(
$_POST as $k => $v){
?>
    <div style="border: 1px solid #000;">
        <?php echo 'div' $n++ . ' - ' $k ' = ' $v?>
    </div>
<?php
    
}
    exit;
}
?>
<html>
<head>
<script type="text/javascript">
function http(){
    if(typeof window.XMLHttpRequest!='undefined'){
        return new XMLHttpRequest();
    }else{
        try{
            return new ActiveXObject('Microsoft.XMLHTTP');
        }catch(e){
            alert('Su navegador no soporta AJAX');
            return false;
        }
    }
}

function request(url, params, id){
    var H=new http();
    if(!H)return;

    H.open('post',url+'?'+Math.random(),true);
    H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    H.setRequestHeader('X-Requested-With','XMLHttpRequest');
    H.onreadystatechange=function(){
        if(H.readyState==4){
            document.getElementById(id).innerHTML = H.responseText;
            H.onreadystatechange=function(){}
            H.abort();
            H=null;
        }
    }
    var p='';
    for(var i in params){
        p+='&'+i+'='+escape(params[i]);
    }
    H.send(p);
}
window.onload = function(){
    var obj = {
        'foo':'bar',
        'baz':'candy',
        'fruits':'vegetable'
    };
    request('b.php', obj, 'content');
};
</script>
</head>
<body>
<div id="content"></div>
</body>
</html>
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos