Hello,
I can’t implement ajax in custom module backend that is my mcp file code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class hijri_date_mcp {
/**
* Constructor
*
* @access public
*/
function __construct()
{
// Make a local reference to the ExpressionEngine super object
$this->EE =& get_instance();
// $this->index();
}
// --------------------------------------------------------------------
/**
* Main Page
*
* @access public
*/
function index()
{
$this->EE->load->library('javascript');
$this->EE->load->library('table');
$this->EE->load->helper('form');
$ajax_method="adjust_date";
$m=str_replace("amp;","",BASE);
$this->EE->javascript->output(array(
'var days=0;
function adjust_date(value)
{
sSource="'.$m.'&C=addons_modules&M=show_module_cp&module=hijri_date&method;='.$ajax_method.'";
$.getJSON( sSource, {
value: value
},
function(result) {
alert(result);
$("#date").html(result);
});
}
$("#plus").click(function(){
adjust_date(1);
});
$("#minus").click(function(){
uadjust_date(-1);
});
' )
);
$this->EE->javascript->compile();
$this->EE->cp->set_variable('cp_page_title', $this->EE->lang->line('hijri_date_module_name'));
$vars['action_url'] = 'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=hijri_date'.AMP.'method=adjust_date';
$vars['form_hidden'] = NULL;
return $this->EE->load->view('index', $vars, TRUE);
}
function adjust_date()
{
$value = $this->EE->input->get_post('value');
$content=file_get_contents(PATH_THIRD."hijri_date/uCal.class.php");
preg_match("/var \\\$adjustment_value=([0-9]{1,});/",$content,$match);
$prev_value=$match[1];
$value=$value+$prev_value;
$content=str_replace("var \$adjustment_value=".($prev_value).";","var \$adjustment_value=$value;",$content);
$f=fopen(PATH_THIRD."hijri_date/uCal.class.php",'w');
fwrite($f,$content);
fclose($f);
include PATH_THIRD.'hijri_date/uCal.class.php';
$d=new uCal;
$d->setLang('ar');
echo $hijri_date=$d->date("l j F Y");
}
}
// END CLASSThe ajax made successful but i didn’t get response callback. when i replace “getJSON” with “post” i get response callback but i got the control panel home page in the response.
thanks,
[Mod Edit: Moved to the Development and Programming forum]
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.