I'm unable to parse a simple JSON-Object returned by PHP after an AJAX-XMLHttpRequest()
. Here is the bizarreness in a nutshell (using a simple json for a test):
On page loads, if PHP sends:
<script>window.onload=function(){JSON2HTML({htm:{world {innerHTML:"hello!"}}});}</script>
my little JSON2HTML function recognizes typeof object and parses the json without complaint.
However, if PHP returns the exact same JSON string (from same PHP variable) via XMLHttpRequest()
{htm:{world:{innerHTML:"hello!"}}}
and onreadystatechange
calls JSON2HTML
to process it then javascript invariably interprets it as typeof string rather than typeof
object and the function fails.
I have set the php response header to "Content-Type:application/json;charset=utf-8"
, stripped all non-ascii characters from the response string and have manipulated the json object in every way imaginable and always get the same result. I've also tried to JSON.parse
the ajax string and get an "unexpected token" error.
Anyone know what could possibly be happening here?