Joomla:我如何输出JsonP文章?

时间:2011-06-27 22:50:13

标签: php json joomla

我想知道是否有一种简单的方法可以将文章输出为JsonP?我需要在应用程序中将其作为Web服务使用

Callback({'response': [{'<div>some random html content</div>'}], 'success': true});

2 个答案:

答案 0 :(得分:3)

http://docs.joomla.org/Ajax_using_MooTools#Generating_JSON_output

<?php
// Set up the data to be sent in the response.
$data = array( 'some data' );

// Get the document object.
$document =& JFactory::getDocument();

// Set the MIME type for JSON output.
$document->setMimeEncoding( 'application/json' );

// Change the suggested filename.
JResponse::setHeader( 'Content-Disposition', 'attachment; filename="'.$view->getName().'.json"' );

// Output the JSON data.
echo json_encode( $data );

答案 1 :(得分:-1)

相关问题