Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/04/2014, 01:36
bathorz
 
Fecha de Ingreso: agosto-2013
Mensajes: 150
Antigüedad: 10 años, 8 meses
Puntos: 29
Respuesta: Recibir datos a través de AJAX

Podría ser con json:
Código Javascript:
Ver original
  1. function inicioEnvio() {
  2.         $(".lista-usuario").html('<img src="http://www.forosdelweb.com/f179/imagenes/1.jpg">');
  3.       }
  4.  
  5.       function llegadaDatos(datos) {
  6.         datos = $.parseJSON(datos);
  7.         $(".lista-artistas").html(datos.artistas);
  8.         $(".lista-canciones").html(datos.canciones);
  9.       }
  10.  
  11.       $(document).ready(function() {
  12.         $("#boton").click(function(e) {
  13.           e.preventDefault();
  14.           var problemas = 'fallo';
  15.           //var title = 'tit_1';
  16.           $.ajax({
  17.             async: true,
  18.             type: "POST",
  19.             dataType: "html",
  20.             contentType: "application/x-www-form-urlencoded",
  21.             url: "proc3.php",
  22.             //data: "titulo=" + title,
  23.             beforeSend: inicioEnvio,
  24.             success: llegadaDatos,
  25.             timeout: 4000,
  26.             error: problemas
  27.           });
  28.         });
  29.       });
Código HTML:
Ver original
  1. <style type="text/css">
  2.       div{border: solid 1px; margin: 2px;}
  3. <div class="lista-artistas">lista artistas</div>
  4.     <div class="lista-canciones">lista canciones
  5. </div>
  6. <button id="boton">Boton</button>
proc3.php
Código PHP:
Ver original
  1. $aArray = array(
  2.    'artistas' => "<li><a href='#'><span class='artista'>artista 1</span></a></li>"
  3.    . "<li><a href='#'><span class='artista'>artista 2</span></a></li>",
  4.    'canciones' => "<li><a href='#'><span class='artista'>cancion 1</span></a></li>"
  5.    . "<li><a href='#'><span class='artista'>cancion 2</span></a></li>"
  6. );
  7. echo json_encode($aArray);