我创造我想要得到从阿贾克斯数据库值的模块。 任何人有这个问题,或者任何例子,请帮助我的解决方案... 谁能给我一个正确的方式为这个.......
这是我的的jQuery
code -
的jQuery(。类型)。绑定(点击,函数(){
VAR feedId = jQuery的(本).attr('身份证');
警报(feedId);
jQuery.ajax({
键入:POST,
网址:模块/ mod_feedback / ajax.php
数据:{类型:feedId},
成功:函数(评论){
//jQuery(".show").html(response);
警报(条);
}
});
});
这是我的 ajax.php
code -
require_once('helper.php');
$评论= modfeedbackHelper :: getFeedbackResultIdea();
回声$审查;
解决方案
首先你要做出一个Ajax调用里面的文件模块,模块它不是一个组成部分,所以它像外部的PHP文件
模块/ mod_feedback / ajax.php
是错误的。你必须做的Ajax调用如下面的相关组件控制器。
的jQuery(。类型)。绑定(点击,函数(){
VAR feedId = jQuery的(本).attr('身份证');
警报(feedId);
jQuery.ajax({
键入:POST,
网址:的index.php选项= com_yourcomponent和放大器;任务= yourcontroller.your_function
数据:{类型:feedId},
成功:函数(评论){
//jQuery(".show").html(response);
警报(条);
}
});
});
然后你的控制器文件中一个命名为 your_function
和具有以下codeS你的函数里面
require_once(JPATH_SITE'/模块/ mod_feedback / helper.php');
$评论= modfeedbackHelper :: getFeedbackResultIdea();
回声$审查;出口;
然后它会工作,否则你要加载的Joomla框架的工作给你的ajax.php它是一个坏主意。尝试按照正确的方法。
希望它帮助。
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.......
this is my jquery
code-
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);
}
});
});
and this is my ajax.php
code-
require_once( 'helper.php' );
$reviews = modfeedbackHelper::getFeedbackResultIdea();
echo $reviews;
解决方案
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
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);
}
});
});
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;
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.
Hope its helps..