JQuery AJAX and module
Posted: Sun Mar 20, 2011 2:08 pm
Hi All, I'm trying to make ajax working in my module, but with poor success and a lot of unsolved (for me..) questions.
(My goal: submit a form and update a db table with ajax, then refresh form fields).
I don't think I'll have problem with db etc., but what is not clear to me is how to use a jquery call from a module page without affect security, because with the JQuery call I loose all benefits of function SetParameters() etc.
Example code:
In action.default.php I have
In ajax.tpl:
In action.ajax.php
In this way, I can't see the echoed "$return" in my action.default.php.
If I put on the top of action.ajax.php the following code, all works fine:
Now, I'd like to know if this is a correct way to use ajax in cmsms, and if, on your opinion, there may be problems about security.
I've read all I've found in this forum and calguy1000's site about the use of ajax in cmsms; and I also tried to use ajaxMS module, studying also Chat module, but I wasn't be able to make ajax work in my module...
thank you
(My goal: submit a form and update a db table with ajax, then refresh form fields).
I don't think I'll have problem with db etc., but what is not clear to me is how to use a jquery call from a module page without affect security, because with the JQuery call I loose all benefits of function SetParameters() etc.
Example code:
In action.default.php I have
Code: Select all
echo $this->ProcessTemplate('ajax.tpl');
In ajax.tpl:
Code: Select all
$.ajax({
type: "POST",
url: "http://www.cms.vmware/modules/MyModule/action.ajax.php",
dataType : 'json',
(...)
$('#message').text(data.msg).show(0);
(...)
});
<div id="message"></div>
In action.ajax.php
Code: Select all
$return['error'] = false;
$return['msg'] = 'OKKKK !!';
echo json_encode($return);
If I put on the top of action.ajax.php the following code, all works fine:
Code: Select all
require '../../include.php'; // (from site's root )
$db=&$GLOBALS["gCms"]->db;
global $gCms;
if (!isset($gCms)) exit;
$mymodule = &$gCms->modules['MyModule']['object'];
Now, I'd like to know if this is a correct way to use ajax in cmsms, and if, on your opinion, there may be problems about security.
I've read all I've found in this forum and calguy1000's site about the use of ajax in cmsms; and I also tried to use ajaxMS module, studying also Chat module, but I wasn't be able to make ajax work in my module...
thank you