Can someone explain this behavior?
in this case:
header("Content-type: text/html");
echo json_encode("error_101");
it works.
in this other case:
header("Content-type: application/json");
echo json_encode("error_101");
it doesn’t work (infinite loading).
But if I pass an array to json_encode, it works in both ways, so this problem exists only with the json values.
It seems a bug!
The outer most data type in a json text must be an array or object.
— http://www.ietf.org/rfc/rfc4627.txt
If you pass PHP’s
json_encodefunction a string, then it will output it as a JavaScript encoded string (instead of throwing an error). I consider this to be a bug.Presumably, whatever is making the HTTP request to this script is having trouble with the invalid JSON response, but has better error recovery for the invalid HTML.