1

I have an error in Javascript

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
...n.now(),dc=/\?/;n.parseJSON=function(a){return JSON.parse(a+"")},n.parseXML=func...

And this is my JavaScript, which gets string from server response

complete: function(response) {
    var results = $.parseJSON(response.responseText);

Error is in the second line because without that line there's no error)

My PHP script: (I use CodeIgniter)

    $str = json_encode($results);
    $this->output->set_output($str);

And an example of the message from server:

{"Thumb_image":"http:\/\/example.com\/img\/thumbs\/9b4138094cb32af906e32f9d033d4748.jpg","Big_image":"http:\/\/example.com\/img\/photos\/9b4138094cb32af906e32f9d033d4748.jpg","Error":""}

Help me please. Why this code is working wrong?

av200
  • 55
  • 5

1 Answers1

0

Try this

 $str = json_encode($results);
 $this->output->set_header('Content-Type: application/json; charset=utf-8');
 echo $str;
Andrii
  • 51
  • 5
  • 3
    Why should the OP try this? How will it solve the problem? Please provide an **explanation** so that other readers can *learn*. – Felix Kling Aug 30 '14 at 18:24
  • I can't use such function as header, because CodeIgniter doesn't allow me that. It writes in error log that headers were already sent. Maybe someone has ideas how can I do this by using CodeIgniter means? – av200 Aug 30 '14 at 19:23
  • This helped. Thank you. I simply had some more bugs – av200 Sep 01 '14 at 12:15