0

I have a Jquery code getting data from ajax call.

$.ajax({
type: 'GET',
url: 'php/upd_dashboard.php',
data: {'name': 'GET_ANUAL_TOTAL_OBJECTIF'},
success: function(data){

    list_total_objectif=data;
},
dataType: 'JSON',
async: false

});

the file upd_dashboard.php, get data from MySql database, and return json result.

echo json_encode($result);

I have no problem when executing this code in localhost, but when I deploy the site I can't get the result of json_encode. by inspecting that in Chrome, I get a character '\ufeff' at the beginning of the json result !!

Chrome inspection result

Is it a problem of encoding? Regards, Hamza.

2 Answers2

4

You can try doing ob_clean(); before sending out json output

ob_clean();//clears the output buffer
echo json_encode($result);

But it seems your $result is just malformed. Is it a string or an array? No character encoding issues there anyway

user3647971
  • 1,069
  • 1
  • 6
  • 13
  • The return is an array, I tried with ob_clean() but still having the same problem – Hamza Berriani Jan 11 '18 at 13:17
  • https://stackoverflow.com/questions/31749384/web-server-response-generates-utf-8-bom-json It really seems there is some file in your project it goes through and it's encoded with BOM as Robert suggested – user3647971 Jan 11 '18 at 13:21
  • 1
    Strange, with ob_clean() it solved my problem, thank you for you help, I appreciate it. – Hamza Berriani Jan 11 '18 at 14:22
0

From what I've found on Google, \ufeff is the Byte Order Mark.

So you probably have your PHP source files in UTF-8 With BOM.

Some PHP versions don't like that and send the BOM output.

Try converting all your PHP source files to UTF-8 Without BOM and it should fix the issue.

Robert Koszewski
  • 583
  • 1
  • 8
  • 17