CodeIgniter Forums
Problem with load->view and jquery - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Problem with load->view and jquery (/thread-32950.html)



Problem with load->view and jquery - El Forum - 08-10-2010

[eluser]vitao1718[/eluser]
guys im trying to do sommenting like this in my ajax code :

CONTROLLER:
Code:
$form = $this->load->view('cliente/form', $data, true);
     $data['form'] = $form;

VIEW:
Code:
[removed]
    $(document).ready(function(){
        $('#formulario').replaceWith("<?php echo $form; ?>");
    });
[removed]


i'm having trouble with that cause the 'echo' is printing the code with line breaks, i just need sommeting to print the $form variable as a string with no format and then i have no errors on javascript.
if i put my view form entire in php with echo it works great, e.g:

Code:
<?php
$data['form_cliente'] = $cliente;

$retorno  = "";
$retorno .= "<tr id='cliente_$cliente->id'>";
$retorno .= "<div>";
$retorno .= "    <td>$cliente->nome</td>";
$retorno .= "    <td>$cliente->id_usuario </td>";
$retorno .= "    <td>$cliente->id_endereco </td>";
$retorno .= "    <td>$cliente->id_endereco </td>";
$retorno .= "    <td>$cliente->id_endereco </td>";
$retorno .= "    <td>";
if (isset($cliente->id)) {
    $retorno .= "        <a href='[removed]'>id)' >Editar</a>";
    $retorno .= "        <a href='[removed]'>id)' >Apagar</a>";
} else {
    $retorno .= "        <a href='[removed]'>Cancelar</a>";
}
$retorno .= "    </td>";
$retorno .= "</div>";
$retorno .= "</tr>";

echo $retorno;
?&gt;


i'm doing this right?or i have a better way to do that?


Problem with load->view and jquery - El Forum - 08-11-2010

[eluser]Georgi Budinov[/eluser]
Just do this in the controller:

Code:
$data['form'] = str_replace("\r\n", "", $form);



Problem with load->view and jquery - El Forum - 08-11-2010

[eluser]vitao1718[/eluser]
not worked... the replace don't works for \n, maybe the string is formated i dont know what to do...


Problem with load->view and jquery - El Forum - 08-11-2010

[eluser]Georgi Budinov[/eluser]
If the problem is the newline(s) ... this should work for you. This way the newlines are taken away.
Can you post the generated html/javascript code that causes errors ?


Problem with load->view and jquery - El Forum - 08-11-2010

[eluser]vitao1718[/eluser]
$form = str_replace("\r", " ", $form);
$form = str_replace("\n", " ", $form);

that works Big Grin