如何从joomla模块中的ajax获取数据库值? [英] how to get database value from ajax in joomla module?
问题描述
我正在创建一个模块,我想在其中从 ajax 获取数据库值.任何人都有这个问题的解决方案或任何例子请帮助我...谁能给我一个合适的方法......
I am creating a module where i want to get database value from ajax. anybody have a solution of this problem or any example please help me... can anyone give me a proper way for this.......
这是我的jquery
代码-
jQuery('.type').bind('click', function() {
var feedId = jQuery(this).attr('id');
alert(feedId);
jQuery.ajax({
type: "POST",
url: "modules/mod_feedback/ajax.php",
data: {"Type":feedId},
success: function(reviews){
//jQuery(".show").html(response);
alert(reviews);
}
});
});
这是我的ajax.php
代码-
require_once( 'helper.php' );
$reviews = modfeedbackHelper::getFeedbackResultIdea();
echo $reviews;
推荐答案
首先,你试图对模块内部的文件进行 ajax 调用,它不是模块的一部分,所以它就像外部的 php 文件
First of all you're trying to make an ajax call to the files inside module and its not a part of the module, so it act like external php file
modules/mod_feedback/ajax.php
是错误的.您必须像下面这样对相关的组件控制器进行 ajax 调用.
modules/mod_feedback/ajax.php
is wrong. You have to make the ajax call to the related component controller like below.
jQuery('.type').bind('click', function() {
var feedId = jQuery(this).attr('id');
alert(feedId);
jQuery.ajax({
type: "POST",
url: "index.php?option=com_yourcomponent&task=yourcontroller.your_function",
data: {"Type":feedId},
success: function(reviews){
//jQuery(".show").html(response);
alert(reviews);
}
});
});
然后在您的控制器文件中添加一个名为 your_function
Then inside your controller file a function named with your_function
并在您的函数中包含以下代码
and have the following codes inside your function
require_once( JPATH_SITE.'/modules/mod_feedback/helper.php' );
$reviews = modfeedbackHelper::getFeedbackResultIdea();
echo $reviews; exit;
然后它就会工作,否则你必须将 Joomla 框架工作加载到你的 ajax.php 中,这是一个坏主意.尝试遵循正确的方法.
Then it will work otherwise you have to load Joomla frame work to your ajax.php its a bad idea. try to follow correct methods.
希望它有所帮助..
这篇关于如何从joomla模块中的ajax获取数据库值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!