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

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

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

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

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

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

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

that works Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB