Unserialize Codeigniter Data - Ajax?

Asked

Viewed 48 times

0

Through the object obj_form, i display in the form the database data:

//Objeto do formulário
function obj_form() {   
    $('[name="id"]').val(obj_permissao.id); 
    $('[name="txt_nome"]').val(obj_permissao.nome);
    $('[name="txt_descricao"]').val(obj_permissao.descricao);   
    $('[name="txt_permissoes"]').val(obj_permissao.permissoes);
    $('[name="sel_grupo"]').val(obj_permissao.grupo);
    $('[name="txt_bgcor"]').val(obj_permissao.bgcor);
    $('[name="sel_situacao"]').val(obj_permissao.situacao);
}

On the line $('[name="txt_permissoes"]').val(obj_permissao.permissoes);, there are serialized data, which brings as a result:

a:8:s:8:"aCliente";s:1:"1";s:8:"eCliente";s:1:"1";s:8:"dCliente";s:1:"1";s:8:"vCliente";s:1:"1";s:9:"aOperador";s:1:"1";s:9:"eOperador";s:1:"1";s:9:"dOperador";s:1:"1";s:9:"vOperador";s:1:"1";}

The question is, how can I deserialize only this line and check the checkbox below if value equals 1.

<tbody>
   <tr>                                             
      <td>Cliente</td>                                              
      <td><input id="" name="aCliente" class="marcar cursor" type="checkbox" value="1"></td>
      <td><input id="" name="eCliente" class="marcar cursor" type="checkbox" value="1"></td>
      <td><input id="" name="dCliente" class="marcar cursor" type="checkbox" value="1"></td>
      <td><input id="" name="vCliente" class="cursor"        type="checkbox" checked="checked" value="1"></td>
    </tr>
    <tr>
      <td>Operador</td>
      <td><input id="" name="aOperador" class="marcar cursor" type="checkbox" value="1"></td>
      <td><input id="" name="eOperador" class="marcar cursor" type="checkbox" value="1"></td>
      <td><input id="" name="dOperador" class="marcar cursor" type="checkbox" value="1"></td>
      <td><input id="" name="vOperador" class="cursor"        type="checkbox" checked="checked" value="1"></td>
    </tr>
</tbody>
  • As I understand it has nothing to do with Codeigniter but with the JS part, is that it? If so and you are using jquery, please take a look at this link, http://api.jquery.com/jQuery.parseJSON/ that can help you

1 answer

0

Hello!

I would like to inform you that I have resolved the following: I used the php-unserialize-js plugin.

And converted the string into an object: var permissoes = phpUnserialize(obj_permissao.permissoes); console.log(permissoes);

Upshot:
aCliente:null aOperador:null dCliente:null dOperador:null eCliente:null eOperador:null vCliente:"1" vOperador:"1"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.