Joomla:我怎么能以JsonP的形式输出一篇文章呢



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

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

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 );

JSON用PHP对其进行编码。

http://php.net/manual/en/function.json-encode.php

最新更新