脚本宝典收集整理的这篇文章主要介绍了php – Joomla – 返回JSON数据的Controller任务,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
public function run ( ) { JFactory::getDocument()->setMimeEncoding( 'application/json' ); JResponse::setHeader('Content-DisposITion','attachment;filename="PRogress-report-results.json"'); JRequest::setVAR('tmpl','component'); $data = array( 'foo' => 'bar' ); echo json_encode( $data ); }
这会返回:
<html XMlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr"> ... </head> <body class="contentpane"> <div id="system-message-container"> </div> {"foo":"bar"} </body> </html>
我想得到:
{"foo":"bar"}
public function run( ) { JFactory::getDocument()->setMimeEncoding( 'application/json' ); JResponse::setHeader('Content-Disposition','attachment;filename="progress-report-results.json"'); $data = array( 'foo' => 'bar' ); echo json_encode( $data ); JFactory::getApplication()->close(); // or jexit(); }
以上是脚本宝典为你收集整理的php – Joomla – 返回JSON数据的Controller任务全部内容,希望文章能够帮你解决php – Joomla – 返回JSON数据的Controller任务所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。