简体   繁体   English

如何在joomla 2.5中使用ajax在自定义模块的帮助文件中调用函数?

[英]How to invoke a function in helper file of a custom module using ajax in joomla 2.5?

i created a custom module with a custom form , i have a 2 dependent drop downs. 我用自定义表单创建了一个自定义模块,我有2个从属下拉列表。 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 但是我坚持在进行ajax调用时必须指定调用函数的URL

<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 .... 我不是在谈论调用组件,它的模块.......我在上面指定的网址不起作用,它显示404错误..

If you are using Joomla 3 or newer version, you can use com_ajax . 如果您使用的是Joomla 3或更高版本,则可以使用com_ajax Here you can find more info about how to set up and use it http://docs.joomla.org/Using_Joomla_Ajax_Interface 在这里,您可以找到有关如何设置和使用它的更多信息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 基本上你需要有helper.php文件在你的模块文件夹,用类名为modMODULE_NAMEHelper ,您可以访问它通过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 . 请注意, MODULE_NAME没有mod_前缀,如果您的模块名为mod_mymodule ,则应使用mymodule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM