0

I am using this code to send response to a request:

$data; //some array

$data has values like

array(4) (
  [nextAvail] => (bool) true
  [thisAvail] => (bool) true
  [count] => (int) 15
  [stream] => (string) [html body goes here] 
)

I am using:

echo json_encode($data);

but surprisingly response I received at browser like:

{"nextAvail":true,"thisAvail":true,"count":15,"stream":null}

I am using jquery post to make request:

$.post(ajaxPath, {
        data: data
   }, 
   function(data) {
   }, "json")

Please suggest what could possibly go wrong while sending response using json_encode, I tested sending response by removing json_encode and simply using

echo print_r($data);

it's sending response with no issues.

Casey
  • 41,449
  • 7
  • 95
  • 125
Manish
  • 1,946
  • 2
  • 24
  • 36

1 Answers1

0

As I was not expecting character encoding could be a possible problem for me, but indeed it was, using utf8_encode() for encoding html response solved the problem.

Manish
  • 1,946
  • 2
  • 24
  • 36