drsl90685154 2010-09-11 10:00
浏览 92

来自PHP脚本的JSON响应包含在<head> </ head> <body> ... <body>中

I am trying to debug a simple PHP/JSON/jQuery problem.

The following PHP script:

header('Content-type: text/javascript');
echo json_encode(array('type'=>'error','message'=>'arg')); 

is being consumed by jQuery but when the line:

var results = jQuery.parseJSON(responseText);

is executed, the jQuery JSON parser gives the following:

uncaught exception: Invalid JSON: <head></head><body><pre>{"type":"error","message":"oops!"}</pre></body>

Obviously the head/body/pre are not supposed to be returned.

I cannot see any hidden characters nor anything out of order in my PHP code..

Any ideas?

  • 写回答

4条回答 默认 最新

  • dongpaipu8394 2010-09-11 10:07
    关注

    Try not to send header('Content-type: text/javascript');

    评论

报告相同问题?

悬赏问题

  • ¥15 vscode问题请教
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM