• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
autoload breaking ajax json response

#1
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.
Reply

#2
I smell BOM.
Reply

#3
BOM is a nasty smell.

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

It puts hidden characters in your files.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#4
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!
Reply

#5
(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?
Reply

#6
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")
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.