Jump to content

How to handle ajax in a back office module controller


sttaq

Recommended Posts

I am trying to make a ajax calls to my back office module controller.

 

So far I have been able to make an ajax call to a ajax.php file situated in my module's root folder and from here I call a static method in my controller. I was looking at some PrestaShop code and found that ajax calls to a admin controller are made like below in one of the back office pages:

...            
$('#someid').autocomplete("ajax-tab.php", {
                delay: 100,
                minChars: 3,
                autoFill: true,
                max: 100,
                matchContains: true,
                mustMatch: false,
                scroll: false,
                cacheLength: 0,
                dataType: 'json',
                extraParams: {
                    id_supplier: '1',
                    id_currency: '1',
                    ajax: '1',
                    controller: 'AdminSupplyOrders',
                    token: "{$token}",
                    action: 'searchProduct'
                },....

Here ajax-tab.php is PrestaShops internal php file. The call to searchProduct resolves to a method having name ajaxSearchProduct and this method is not static. Now, when I try to do the same in module's controller I get an exception that module cannot be found. I would like to know if making ajax requests in this way is possible and if it is then what should I do to make it work?

 

Alternately, I can use the AdminSupplyOrders but because this javascript is called from a different tab the token is not set to that needed by AdminSupplyOrders and if I try with it I get a security exception. So if I know how to get a token for a AdminSupplyOrders other than the current one then that can help as well.

 

Thanks

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...