Welcome Guest, Not a member yet? Register   Sign In
Problem with load->view and jquery

guys im trying to do sommenting like this in my ajax code :

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

        $('#formulario').replaceWith("<?php echo $form; ?>");

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:

$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;

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

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

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

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

[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 ?

$form = str_replace("\r", " ", $form);
$form = str_replace("\n", " ", $form);

that works Big Grin

Theme © iAndrew 2016 - Forum software by © MyBB