2

i created a custom module with a custom form , i have a 2 dependent drop downs. i want to populate te drop down of second one based on first . But i am stuck with the url that must be specied to call the function when making ajax call

<script>
$(document).ready(function() {
     $( "#strCountry" ).change(function(){
          var id = $( "#strCountry option:selected" ).val();
          if(id>0){
              $.ajax({
                  url: "module=mycontact&task=getgetStates&country_id="+id,
                  success: function(responseText){
                         document.getElementById('strCountry').innerHTML=responseText;
                   }
              });
          }
     });
});
</script>

I am not talking about making call to component , its module ....... the url i specified above doesnt work , its showing a 404 error ....

Sabz
  • 35
  • 3
  • I assume you have installed the Ajax Component that would normally come prepacked with Joomla 3.x – Lodder Feb 13 '14 at 10:26
  • check this http://stackoverflow.com/questions/20853947/how-to-get-database-value-from-ajax-in-joomla-module/20854508#20854508 This question will ask many times in different ways. – Jobin Feb 13 '14 at 10:37
  • thanks for the reply .....lemme check – Sabz Feb 13 '14 at 10:50
  • @Jobin Jose : my doubt is in ur url u specified option = com_yourcomponent ...... but this is a module , do i need to create a component then ? – Sabz Feb 13 '14 at 10:56
  • First of all you cannot make an ajax call to a module. If you're using Joomla3.x it have a basic component for this purpose called com_ajax other wise you have to use related components (like this module is related to any component you can use that controller for this purpose) Hope now its clear for you.. – Jobin Feb 13 '14 at 11:13
  • Well if you could answer @Lodder question, it would be easier to help you. – di3sel Feb 13 '14 at 13:09

1 Answers1

0

If you are using Joomla 3 or newer version, you can use com_ajax. Here you can find more info about how to set up and use it http://docs.joomla.org/Using_Joomla_Ajax_Interface

Basically you need to have helper.php file in your module folder, with class named modMODULE_NAMEHelper and you can access it's methods via url: index.php?option=com_ajax&module=MODULE_NAME&method=METHOD_NAME

Please note, that MODULE_NAME is without mod_ prefix, you if your module called mod_mymodule, you should use mymodule.

di3sel
  • 2,002
  • 15
  • 24