The other two were on the right track, you need to remember that when you make your AJAX call, you cannot directly access the php file in Joomla. Therefore, it is better to call your module instead. In this case, check the module for variables in POST or in the URL.
I am a big fan of jQuery ajax, it is much more autonomous than the method used by the one who built this shoutbox.
$( "#addShout" ).click( function(event, ui) { $.ajax({ type: 'GET', url: "<?php echo JURI::base() . "index.php?option=mod_mymodule&task=getCustomerJson&selectedCustomer="?>" + encodeURIComponent(value), success:function(data){ $('#shouts').append(data); }, error:function(){ $('#errors').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>'); } }); });
Then, as I mentioned in my commentary on Valentine, you:
$task = JRequest::getVar('task'); if($task == "getCustomerJson"){mySuperHelper::getCustomerJson();}
Call only the necessary functions when variables exist.
To explain part of the process, it looks something like this:
- If there are no variables in the POST or URL, it will simply display the module as Joomla expects.
- If a variable is found, call the method to add it to the database and a javascript function that will add it to the display. Also prevent a normal display.
The module you referenced was quite interesting. Helper functions that reference the main file do what the model would normally handle in MVC, and Javascript also looked like everything. If you really want to understand how this works, you really need to insert the fatAjax.js file as it contains all AJAX and sets the variables that mod_shoutbox.php listens for.
source share