1

I would like to call a controller function and after that I would like to update my view with an ajax call.

Therefore I call my controller function from an ajax script using this url:

url: "index.php?option=com_mycomponent&task=component.save"

Everything seems fine, but I cannot access my form inputs in the controller.

$jinput = JFactory::getApplication()->input;
$data = $jinput->get('jform', 'default_value', 'filter');

$data stays empty.

When I call the function from a normal Joomla button in the form, everything is fine and all values from the form are available in the controller.

I would like to call my controller function and afterward I would like to update my view with an ajax call.

migrated from stackoverflow.com May 23 '14 at 17:56

This question came from our site for professional and enthusiast programmers.

  • Are you using a post method for the ajax call? – Pep Lainez May 24 '14 at 16:55
1

I think you may want to try it like this:

$data  = $this->input->post->get('jform', array(), 'array');
1

assuming you are using joomla 3, you can use jquery for this functionality:

JHtml::_('jquery.framework'); // make sure jquery is loaded
<script type="text/javascript">
jQuery.post('index.php?option=com_mycomponent&task=component.save', 
jQuery( "#yourformid" ).serialize(), function(data, 
statustxt){ jQuery('#resultdiv').html=data; })
</script>

This should return the result to an element . Docs for jQuery.post() is found here http://api.jquery.com/jquery.post/. The post-functionality should add the data from your form as post-variables for joomla to read. To see all incoming post-variables in php write

print_r($_POST); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.