I'm developing a custom plugin for Joomla 3. I'm trying to make an ajax call to my plugin. I've looked into the Joomla Ajax Interface and followed what was described. But when I make the call, the json response is empty, even if I'm echoing a value.
Here is my PHP code:
class plgContentMyPlugin extends JPlugin
{
public static function onAjaxSendMail()
{
//Get the app
$app = JFactory::getApplication();
$data = "test";
//echo the data
echo json_encode($data);
//close the $app
$app->close();
}
}
Here is my Ajax request:
jQuery.ajax(
{
type: "POST",
url: "index.php?option=com_ajax&plugin=myplugin&method=onAjaxSendMail&format=json",
success: function(data)
{
var response = jQuery.parseJSON(data);
console.log(response);
}
});
When I receive the response, the data variable contains an empty array.
What am I doing wrong? Thank you.