Tab and pre wrapped around JSON output in Chrome

落爺英雄遲暮 提交于 2019-12-02 08:38:51

You need to remove whatever code adds the <pre> tag. This causes your response to be invalid JSON (the whitespace to prettyprint it is not a problem though) and thus makes jQuery fail when parsing it.

I couldn't see anything in the PHP docs about the JSON response being wrapped in <pre> but you could surely try it without the flag. I'd also make sure to check if the tag is actually in your response. If you use view-source and have a JSON-pretty-printing browser extension installed it might be added by that extension and not be in the actual JSON handled by your JavaScript code.

hmmm,I was searching for an correct answer my self but none of them worked for. but I tried to do as following and it worked for me ...

1- I set the content type to application/json

2- I used the die(json_encode($this->data)) instead of echo json_encode($this->data)

hope it will work for you although I guess its a bit too late :D forgive me for answering an old question I recently run into same issue myself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!