Ver Mensaje Individual
  #6 (permalink)  
Antiguo 13/01/2011, 03:51
Krato
 
Fecha de Ingreso: mayo-2008
Mensajes: 117
Antigüedad: 16 años
Puntos: 0
Respuesta: Pasar tabla html a otro archivo

Bueno, escribo de nuevo porque ya lo he resuelto y haber si a otro le puede valer la opción:

Código Javascript:
Ver original
  1. jQuery("#add_valoracion").dialog({
  2.                 autoOpen: false,//remove this and the click to aut oopen
  3.                 bgiframe: true,
  4.                 dialogClass: "valor",
  5.                 position: 'top:0',
  6.                 height:1000,
  7.                 width: 1300,
  8.                 modal: true,
  9.                 resizable: false,
  10.                 buttons: {
  11.                     'Cancelar': function() {
  12.                         jQuery(this).dialog('close');
  13.                     },
  14.                     'Guardar': function() {
  15.                         var html_valora = jQuery("#valoracion").contents().find("#jSheetEditPane_0_0").html();
  16.                        
  17.                         var s = "";
  18.                         jQuery(html_valora).each(function() {
  19.                             s +=  compacta(this);
  20.                             s = unescape(s);
  21.                         });
  22.                        
  23.                         var arra = s.split("\n");
  24.                         var num = arra.length;
  25.                         var ref = jQuery("#ref").val();            
  26.                         for (i=0; i < num; i++) {
  27.                             tex = arra[i];
  28.                             agrega(i, ref, tex);               
  29.                         }      
  30.                         jQuery(this).dialog('close');
  31.                     }
  32.                 },
  33.                 open: function(event, ui) {
  34.                
  35.                     $('.valor').css('top', 20);
  36.                 }
  37.             });
  38.            
  39.             function agrega(i, ref,tex){
  40.             var url = "include/valoracion.php";
  41.                         $.ajax({
  42.                             type: "POST",
  43.                             url: url,
  44.                             data: "ref="+ref+"&html="+escape(tex),
  45.                             success: function(msg){        
  46.                             },
  47.                             error: function(msg){
  48.                                 alert(msg);
  49.                             }
  50.                         });
  51.             }
  52.            
  53.            
  54.             function compacta(node) {
  55.                 var result = "";
  56.                 if (node.nodeType == 1) {
  57.                     result += "<" + node.tagName;
  58.                     hasClass = false;
  59.                    
  60.                     var n = node.attributes.length;
  61.                     for (var i = 0, hasClass = false; i < n; i++) {
  62.                         var key = node.attributes[i].name;
  63.                         var val = node.getAttribute(key);
  64.                         if (val) {
  65.                             if (key == "contentEditable" && val == "inherit") {
  66.                                 continue;
  67.                                 // IE hack.
  68.                             }
  69.                             if (key == "class") {
  70.                                 hasClass = true;
  71.                             }
  72.                            
  73.                             if (typeof(val) == "string") {
  74.                                 result += " " + key + '="' + val.replace(/"/g, "'") + '"';
  75.                             } else if (key == "style" && val.cssText) {
  76.                                 result += ' style="' + val.cssText + '"';
  77.                             }
  78.                         }
  79.                     }
  80.  
  81.                     if (node.tagName == "COL") {
  82.                         result += '/>';
  83.                     } else {
  84.                         result += ">";
  85.                         var childResult = "";
  86.                         jQuery(node.childNodes).each(function() {
  87.                             childResult += HTMLtoCompactSource(this);
  88.                         });
  89.                         result += childResult;
  90.                         result += "</" + node.tagName + ">";
  91.                     }
  92.                 } else if (node.nodeType == 3) {
  93.                     result += node.data.replace(/^\s*(.*)\s*$/g, "$1");
  94.                 }
  95.                 return result;
  96.             }

y el siguiente php:

Código PHP:
Ver original
  1. <?php
  2. $ref =$_POST["ref"];
  3. $contenido = $_POST["html"];
  4. $contenido = stripslashes($contenido);
  5. $contenido = str_replace("%u20AC","€",$contenido);
  6. $myFile = "../archivos/".$ref."/valoracion.html";
  7. $fh = fopen($myFile, 'a') or die("can't open file");
  8. fwrite($fh, $contenido);
  9. fclose($fh);
  10. ?>

Al final lo que he hecho es recorrer el html de la tabla y parsearlo de manera correcta. Y la verdad queda de lujo!

Lo dicho espero que ha alguien le valga.

Un saludo y gracias por las contestaciones masterpuppet

Eric