I have a setup where I am using ajax to retrieve data from the database. Right now I'm trying to nail down sending an array from the php file to the javascript where my ajax is run.
Currently I'm using json encode to send the data from the php file
echo json_encode($send_array);
And then I am trying to retrieve it as an array on the javascript side with a json parse on the response text.
JSON.parse(xhttp.responseText);
This is where it get's weird. If I just print out or display xhttp.responseText, I get a text representation of my array.
[1,2,3,4,5,6,7]
But if I run JSON.parse on it, I get an syntax error of an unexpected '<'.
Digging further, if I do xhttp.responseText[0], it returns '<'.
Testing it further, I found xhttp.responseText[4] returns '@' which is the fourth character in the comment at the very top of my php file.
I need help figuring out why xhttp.responseText returns text in the correct format, but trying to retrieve only part of the responseText or trying to parse on it returns the top of my php file instead.