Hello,
I'm trying to customize a certain component to use JSON and the system-message-container to get the response. Resources I tried to follow are:
http://joomlablog.ru/dokumentatsiya/dlya-razrabotchika/api/542-jresponsejson-vozvrashchaem-dannye-v-formate-json
And
https://docs.joomla.org/JSON_Responses_with_JResponseJson
But I cant get it to work.
My scripts:
jQuery(function($) {
$(document).ready(function() {
$('button.submit').on('click', function(){
$('#vote-form').submit();
return false;
});
$('#vote-form').submit(function(event) {
var domForm = document.getElementById('vote-form');
if (!document.formvalidator.isValid(domForm)) {
return false;
}
console.log(url);
$.getJSON(index.php?option=com_polls&task=
poll.vote&format=json', {data: data})
.done(function(r) {
if (!r.success && r.message)
{
alert(r.message);
}
if (r.messages)
{
Joomla.renderMessages(r.messages);
}
if (r.data)
{
alert(r.data.myfirstcustomparam);
alert(r.data.mysecondcustomparam);
}
})
.fail(function() {
alert('Ошибка Ajax запроса!');
})
.always(function() {
alert('Ajax запрос завершен');
});
return false;
});
});
});
My controller part:
public function vote() {
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication();
$model = $this->getModel('poll');
$params = JComponentHelper::getParams('com_polls');
$user = JFactory::getUser();
$id = $app->input->getInt('poll_id', 0);
$app->enqueueMessage('Some error message', 'warning');
$result = true;
echo new JResponseJson($result, 'blbblbl');
jexit();
}
This echo's the json response in a reloaded blank page. The console.log gives me the right expected url.
Anyone could point me in the right direction?