0
votes

I am a beginner in joomla .I have a contact form in the front end where i want to get the dropdown of states when a country is selected.This contact form display is at myproject/components/com_contact/views/contact/tmpl/default_form.php . I have a country drop down there . I want to make an ajax call to the function filterState() in the controller of contacts . this is my ajax code

`<script>
$( document ).ready(function() {
       $( "#jform_contact_country" ).change(function(){
          var id = $( "#jform_contact_country option:selected" ).val();
          alert(id); 
          $.ajax({
              url: "index.php",
              data: 'option=com_contact&task=filterState()&country_id='+id,
              success: function(data) {
                    alert('succes');
                }
              }); 
        });
    });
</script>` 

method filterStae is inside the contact.php which is inside myproject/components/com_contact/controllers/ . But when i change the country this function is not called and call goes to index.php and is not going to this page ? how to actually invoke this function ?

1

1 Answers

0
votes

Try to change code to this one:

<script>
  $(document).ready(function() {
    $("#jform_contact_country").change(function(){
      var id = $("#jform_contact_country option:selected").val();
      alert(id); 
      $.ajax({
        url: "index.php?option=com_contact&task=CONTROLLER_NAME.filterState&country_id="+id,
        success: function(data) {
          alert('succes');
        }
      }); 
    });
  });
</script>

Change CONTROLLER_NAME with your controller filename in /controllers/ As you can see from my code, to access controller's method, task value should be CONTROLLER_NAME.METHOD_NAME