php - Tab and pre wrapped around JSON output in Chrome -
i using simple code print array json structure.
header('content-type: application/json'); echo json_encode($this->data, json_pretty_print);
i'm using chrome version 28.0.1500.95 m. odd reason output wrapped in pre tag tab character (i.e. \t
) @ beginning.
json seems parsing okay still tab character when no data sent. how can fix ?
<pre style="word-wrap: break-word; white-space: pre-wrap;"> { "title": "node", "items": [ { "label": "do stuff", "icon": "..\/ui\/images\/icons\/16x16\/icon.png", "action": "dostuff" } ] }</pre>
edit: here's code on jquery side:
$.ajax({ url : "/myproject/getmenu/", type : 'get', datatype: "json", success : function(data) { //alert(json.stringify(data,undefined,2)); if (jquery.isemptyobject(data)) { return; } title = data.title; items = data.items; selected.contextpopup({ title : title, items : items }); } });
you need remove whatever code adds <pre>
tag. causes response invalid json (the whitespace prettyprint not problem though) , makes jquery fail when parsing it.
i couldn't see in php docs json response being wrapped in <pre>
surely try without flag. i'd make sure check if tag in response. if use view-source , have json-pretty-printing browser extension installed might added extension , not in actual json handled javascript code.
Comments
Post a Comment