download1002 2015-11-07 23:07
浏览 31

responseText返回我的php文件的顶部

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.

  • 写回答

1条回答 默认 最新

  • dongyi2889 2015-11-08 00:07
    关注

    Now Solved. It turns out the problem was that my php file had html styled comments at the top. These were getting send along with the data that was echoed.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊