Tengo este código que hace lo siguiente:
1.envia formulario post/ajax al servidor.
2.el servidor procesa la petición y devuelve un array con 3 variable en formato JSON
1.save_result. si es numerico, todo bien.3.carga el mensaje de error/exito y el formulario gravado si todo ok.
2.message. un mensaje, con etiquetas html
3.saved_form. el formulario, una vez gravado (<form id='dddddd'..> bl bla bla </form>"
...y lo hace todo bién. 0 problemas.
Dicho formulario recoje valores de parametrización de la web: es parte de un pseudo-csm que estoy montando, con lo que, para más lio, los campos contienen como dato, html y javascript. Esto, convierte la variable JSON en algo inmenso e ilegible, pero funciona. Pongo ejemplo.
Código PHP:
   "{\"save_result\":\"1\",\"message\":\"<img whidth=\\\"25\\\" height=\\\"25\\\" src='http:\\/\\/10.1.1.71\\/wturing\\/cssbackend\\/img\\/ok.ico'>\\n<p>save ok<\\/p>\",\"saved_form\":\"<form class=\\\"form_edit\\\" id=\\\"form_20_1_379850\\\" action=\\\"http:\\/\\/10.1.1.71\\/wturing\\/index.php\\\" method=\\\"POST\\\" name=\\\"form_20_1_379850\\\" onsubmit=\\\"subirArchivo('form_20_1_379850')\\\">\\r\\n   <input type='hidden' name='wt_template' value='form_save'>\\r\\n<input type='hidden' name='wt_packet' value='20'>\\r\\n       <div class='(divclass)'>\\r\\n        <label for=\\\"\\\" id=\\\"\\\">id<\\/label>\\r\\n        \\r\\n        <br>\\r\\n        <input type='text' name='id' id='id' value='1'>\\r\\n    <\\/div>    <div class='(divclass)'>   .............   BLABLABLA   .................">(camptr)</label>rn        (requerit)rn        <br>rn        <input type='text' name='(camp)' id='(camp)' value='(value)'>rn    </div></textarea>rn        </div>        <div class=''>rn            <label for='t_textarea' id=''>t_textarea</label>rn            rn            <br>rn            <textarea name='t_textarea'  rows='4' id='t_textarea'>        <div class=''>rn            <label for='(camp)' id=''>(camptr)</label>rn            (requerit)    </div>    <div class='(divclass)'>rn        <label for="\\\" id=\\\"\\\">mail_pwd<\\/label>\\r\\n        \\r\\n        <br>\\r\\n        <input type='text' name='mail_pwd' id='mail_pwd' value='xypato'>\\r\\n    <\\/div>\\r\\n   <div class=''>\\r\\n      \\r\\n       <input type=\\\"submit\\\" value=\\\"gravar\\\" (filtres) class=\\\"\\\" name=\\\"save\\\">\\r\\n   <\\/div>\\r\\n<\\/form>\\r\\n\"}" 
    Código PHP:
       include('json.php');
    $json = new Services_JSON();
    return $json->encode($array); 
    Código PHP:
   <script type="text/javascript">
jQuery(function($){
    $('form.form_edit').live('submit',function(){ 
        idform=$(this).attr('id');
        ur=$(this).attr('action');
        params=$(this).serialize();
        $.post(ur,params, function(resposta) { 
           resp=eval('('+resposta+')');
           if(!isNaN(resp['save_result'])){
                $('.divform[idform='+idform+']').html(resp['saved_form']);
            }
            $('.message[idform='+idform+']').html(resp['message']);
        });
        return false
    })
  })
</script> 
   Leyendo por la web, la solución que mas me ha convenido, es hacerlo con iframes. Bajé un script y adaptado queda así:
Código PHP:
   <script type="text/javascript">
function subirArchivo (pidform) {
        var ifm = document.createElement('iframe');
        ifm.style.display = 'none';
        ifm.name = 'tmpfrm';
        ifm.onload = function (e) {}
        var eform = document.getElementById(pidform);
        eform.target = 'tmpfrm';
        var ebody = document.getElementsByTagName('body')[0];
        ebody.appendChild(ifm);
        eform.submit();
 
        ifm.onload = function (e) {
            var resp = ifm.contentWindow.document.body.innerHTML;
            var respuesta = (JSON)?JSON.parse(resp): eval('(' + resp + ')'); <----Y DE AQUÍ, NO PASA
            alert(respuesta['save_result']);
            if(!isNaN(respuesta['save_result'])){
                $('.divform[idform='+pidform+']').html(respuesta['saved_form']);
            }
            $('.message[idform='+pidform+']').html(respuesta['message']);
        }
    }
</script> 
   Pero si el valor devuelto json es simple, sí funciona.
Código PHP:
   {"save_result\":\"1\",\"message\":\"hola","saved_form\":\"que tal\"} 
    Alguna sugerencia del error? ...o del planteamiento?
Gracias de antemano.
 

