CodeIgniter Forums
autoload breaking ajax json response - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: autoload breaking ajax json response (/showthread.php?tid=67704)



autoload breaking ajax json response - lanoux - 03-29-2017

I experiment an odd things on codeigniter. Adding my own library, model, or config in the autoload breake my json response in ajax request.

The installation of CI is totally fresh. No url rewriting, nothing change inside the config.php


when i load like this my own component :


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

$autoload['packages'] = array();
$autoload['libraries'] = array('email');
$autoload['drivers'] = array();
$autoload['helper'] = array('user');
$autoload['config'] = array('google');
$autoload['language'] = array();
$autoload['model'] = array('user_model'); 


user_helper.php google.php and User_model.php contain strictly nothing

user_helper:

PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
if ( ! 
function_exists('user'))
{
    function 
user() {}



User_model:
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class 
User_model extends CI_Model
{
    public function 
user() {}


google:

PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
$config['lang'] = "fr"


like this we can't say it's my coding who put the mess.

and the ajax call looke like this :

Code:
$(document).ready(function() {
    $.post(
        "http://www.codeigniter.dev/index.php/ajaxrequest/test",
        {
            id: 'test'
        },
        function(data)
        {
            console.log(data);
        },
        "json"
    );
});

the result looke like this
[Image: ajaxResponse1.png]

As you can see nothing appear with the console log and no response in json format.


If i replace the autoload with this :
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

$autoload['packages'] = array();
$autoload['libraries'] = array('email');
$autoload['drivers'] = array();
$autoload['helper'] = array();
$autoload['config'] = array();
$autoload['language'] = array();
$autoload['model'] = array(); 

and i load those missing file inside the controler like this :
PHP Code:
<?php 
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Test extends CI_Controller
{
    public function 
index()
    {
        
$this->load->helper(array('user'));
        
$this->load->model(array('user_model'));
        
$this->config->load('google');
        
        
$this->load->view('test_message');
    }


Tadam it's magic :
[Image: ajaxResponse2.png]

the ajax and json respond normally.


I must add than when i autoload only one of my own file it's worke normally.

It is normal? CI can't autoload more than one of my file without breaking json response?
Like you can see i have done nothing inside the project for not polluate the error process.


RE: autoload breaking ajax json response - Narf - 03-29-2017

I smell BOM.


RE: autoload breaking ajax json response - InsiteFX - 03-29-2017

BOM is a nasty smell.

Check your editor setting and tell it not to use the BOM.

It puts hidden characters in your files.


RE: autoload breaking ajax json response - lanoux - 03-30-2017

thanks guys you save my life, you deserve a big kiss....or a beer Smile

Didn't know why 2 of my files were with BOM (normally my text editor is parameterize for not including this stupid thinks)

But really a big thanks to both of you!


RE: autoload breaking ajax json response - coolcurrent - 11-25-2017

(03-30-2017, 12:07 AM)lanoux Wrote: thanks guys you save my life, you deserve a big kiss....or a beer Smile

Didn't know why 2 of my files were with BOM (normally my text editor is parameterize for not including this stupid thinks)

But really a big thanks to both of you!

How did you find the file with BOM encoding?


RE: autoload breaking ajax json response - InsiteFX - 11-26-2017

If you look at the files there will be weird characters at the beginning of the file, like hex code.

At the beginning of the HTML page.

BOM:

FEFE 2D30 2D63 2D53 2D4D 0021 ("Big edian")
FFFE 302D 632D 532D 4D2D 2100 ("Little edian")