Jump to content


Unexpected token json


  • Please log in to reply
4 replies to this topic

#1 Julio

Julio

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts
  • LocationBrazil

Posted 09 August 2018 - 08: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?

#2 larasmith

larasmith

    Advanced Member

  • Members
  • PipPipPip
  • 199 posts
  • LocationPhilippines

Posted 13 August 2018 - 12:02 AM

Hi Julio!

 

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

 

Lara



#3 Julio

Julio

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts
  • LocationBrazil

Posted 14 August 2018 - 10:43 PM

Hi.

Yes. I'm using CI.

About the error i fixed it.

Thanks.

#4 wildfandango

wildfandango

    Member

  • Members
  • PipPip
  • 24 posts

Posted 27 August 2018 - 04: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);



#5 wildfandango

wildfandango

    Member

  • Members
  • PipPip
  • 24 posts

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);
    }

 

 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users