I am developing a Joomla component. In javascript I use jQuery.ajax() for making a (php) controller method put data (from javascript) into the database. However, after installing the component on one Joomla site, it works, but on another site the data passed through jQuery.ajax() is not obtained by JInput::get().
The (simplified) ajax request is as follows:
jQuery.ajax( {
'type': 'POST',
'url': 'index.php?option=com_example&task=examplecontroller.handleAjaxRequest',
'data': { 'ajaxData': 'test' },
'success': function( ajaxResult ) {
alert( ajaxResult );
}
} );
The (simplified) controller method:
public function handleAjaxRequest()
{
$app = JFactory::getApplication();
$input = $app->input;
echo $input->get( "ajaxData", "defaultValue", "string" );
$app->close();
}
On one of my sites, an alert with text 'test' is shown as expected. But on the other site, an alert with text 'defaultValue' is shown, indicating that JInput::get() did not find data item 'ajaxData' and used the default value provided in its second parameter.
Both sites are installed on the same domain, each on a different subdomain. So same php version, Joomla upated to the same version (3.9.26), using same jQuery version (in jquery.min.js it says v1.12.4-joomla).
Anyone any idea what or which setting could cause this? I would really appreciate it, because I have no idea any more.
EDIT:
I inspected the $_POST and the $_GET variables: url parameters 'option' and 'task' are present (in $_GET) on both sites, but url parameter 'ajaxData' is only present (in $_POST) on one of the sites.
The .htaccess files are exactly the same on both sites.