Chase Florell
Chase Florell

Reputation: 47387

Joomla: How can I output an article as JsonP?

I'm wondering if there's an easy way to output an article as JsonP? I need to consume it in a application as a web service

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

Upvotes: 1

Views: 1903

Answers (2)

Tarek
Tarek

Reputation: 3798

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

Upvotes: 3

jjwdesign
jjwdesign

Reputation: 3322

JSON Encode it with PHP.

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

Upvotes: -1

Related Questions