⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Unexpected token json



Julio

Julio
  • profile picture
  • Member

Posted 09 August 2018 - 20:29 PM

Hi,

I followed the exemple instructions to setup my first crud without composer and when load the page i got this error:

SyntaxError: unexpected token < in json at position 2

On chrome console:
[Violation] Forced reflow while executing javascript

Please, should anyone help me?

Or tell me how to debug this and how to solve this error?

larasmith

larasmith
  • profile picture
  • Member

Posted 13 August 2018 - 00:02 AM

Hi Julio!

 

Are you using CodeIgniter as framework? I can help you if that's the case.

 

Lara


Julio

Julio
  • profile picture
  • Member

Posted 14 August 2018 - 22:43 PM

Hi.

Yes. I'm using CI.

About the error i fixed it.

Thanks.

wildfandango

wildfandango
  • profile picture
  • Member

Posted 27 August 2018 - 16:06 PM

Hi, i have the same error in this CRUD, can un share your solution?

 

        $crud = $this->GCRUD_getGroceryCrudEnterprise();
        $crud->setTable('login_usu');
        $crud->setSubject("Datos del usuario","Lista de usuarios");
        $crud->setTheme("bootstrap-v4");

        $crud->columns(['id','nombre','email']);
        $crud->fields(['id','nombre','email','clave']);

        $crud->setPrimaryKey('id',"login_usu");

        $crud->displayAs([
            'id' => 'ID',
            'nombre' => 'Nombre',
            'email' => 'eMail',
            'clave' => 'Clave'
            ]);

        $crud->defaultOrdering('login_usu.nombre', 'asc');

        $crud->requiredFields(['nombre','clave','email']);
        $crud->readOnlyFields(['id']);

        $output = $crud->render();
        $this->load->view('login_crud.php',$output);


wildfandango

wildfandango
  • profile picture
  • Member

Posted 28 August 2018 - 10:58 AM

In my case the problem is that you cannot call $this->load->view('login_crud.php',$output); directly.
 
It says so clearly in the documentation and I have done it hundreds of times correctly :(
 
The call to the view should be like this:
 

$this->GCRUD_output('fullscreen_crud.php',$output);

 

where

 

    function GCRUD_output($template = "",$output = null) {
        if (isset($output->isJSONResponse) && $output->isJSONResponse) {
            header('Content-Type: application/json; charset=utf-8');
            echo $output->output;
            exit;
        }


        $this->load->view($template,$output);
    }