1

I come asking because I can't find any more trail for my problem. Hope someone could help me :)

Since several week, all in a sudden, my json got a weird unreadable character, provoking ajax request to raise an error instead of success state. My code didn't change. I tried more tips like a simple boolean as return in the json. But nothing can help. I lighten the code in order to avoid possible wrong character data.

I get an SyntaxError: Unexpected '' on line 1 when i try to validate on jsonlint he detects the wrong character

JSONLint error

my code server side in php is the following :

$resultat = array();
$resultat['Success'] = true;
echo json_encode($resultat);

and my js ajax request :

var param = [{ name: "tbActionToDo", value: "InitialiseMailbox" }];

$.ajax({
    type: "POST",
    url: "actions/DatasourceEmail.php",
    data: param,                   
    dataType: "json",
    dataFilter: function(data, type){ 
       return data;
    },
    error: function(xhj, statut, thrown){
        Notify("Danger", xhj.responseText);
    },
    success: function(result){
        // do something
    }
});

Thanks for your time and help !!

Phil
  • 157,677
  • 23
  • 242
  • 245
Iainh
  • 33
  • 4
  • 1
    looks like there is something output _before_ the `echo json_encode...`. In an included file maybe? Also check correct encoding of scripts (utf-8 without BOM) – Jeff Sep 09 '18 at 08:59
  • You have an empty line at the beginning of json – Nomad Webcode Sep 09 '18 at 09:13
  • can you try with ob_clean() before the echo line? If works, you are printing something before this code. – Nomad Webcode Sep 09 '18 at 09:14
  • To elaborate on @Jeff's comment, see point #4 here ~ https://stackoverflow.com/a/8028987/283366 – Phil Sep 09 '18 at 09:14
  • 1
    I check every solution proposed. but the obclean() is working. I don't understand why before it was working or what happened. Since I'm retrieving email data from a mailbox server, maybe some characters or content provoke the error. By the way it's working. thanks to all of you for your reactivity – Iainh Sep 09 '18 at 09:26

0 Answers0