Jump to content

[SOLVED] how to run module function with ajax query?


Recommended Posts

Sorry. Actually i am new for prestashop.

 

 

i am trying to create a backend module. So i create a php file and one tpl file. when i install this module i can able to see a icon in back end. when i click this image i want to execute a function in the php file using ajax.
 
for example
 
mymodule.php
 
if(isset($_REQUEST['id']))
 
{
 
$res = "123";
 
echo $res;
 
 
 
 
in my tpl file(mymodule.tpl)
 
function abc()
 
{
 
$.ajax({
 
type: 'POST',
 
url: 'mymodule.php',
 
data: 'id=1',
 
success: function(data)
 
{
 
alert(data);
 
}
 
});
 
 
}
Link to comment
Share on other sites

no. all the things are working. but now my requirement is when i click an icon from this tpl file i need to acccess one of the function from the php file

 

 

 

now the problem is only the url. I  give the direct url in ajax function   like....

 

 http://host name/modules/mymodule/mymodule.php

Edited by franklinfs (see edit history)
Link to comment
Share on other sites

create php file, for example ajax.php with content:

<?php


include_once('../../config/config.inc.php');
include_once('../../init.php');
include_once('mymodule.php');


$mymodule = new mymodule();
$mymodule -> somefunctionfrommodule();

then in call this file in your ajax call.

code defined in public function somefunctionfrommodule(); will be called then :)

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...