ThinkPHP Resource interpreted as Document but transferred with MIME type application/json 导致js无效

时间:2022-09-24 15:41:27

ThinkPHP中当使用

$this->ajaxReturn(array('file'=>$outputFileName));

返回数据时header标签会被强行改成Content-Type:application/json; charset=utf-8;即使在之前你设置header(‘Content-Type:text/html; charset=utf-8’);也不行。如果你的请求数据类型和返回数据类型不同就会出现错误:
ThinkPHP Resource interpreted as Document but transferred with MIME type application/json 导致js无效

Resource interpreted as Document but transferred with MIME type application/json

后续js无法执行。

解决办法:
可使用一下方法解决:

header('Content-Type:text/html; charset=utf-8');
echo json_encode($data);

ThinkPHP Resource interpreted as Document but transferred with MIME type application/json 导致js无效