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#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。