Jump to content

ajax custom page


isabella moreno

Recommended Posts

Hi everybody

I'm searching for a solution about my custom page.

I need to post on my custompage.tpl my prestashop a simple string "Lorem ipsum" with ajax response from CustomPageController.php using json format.

Can you help me?

Thank You!

 

 

controllers/front/CustomPageController.php

 

public function initContent(){
   parent::initContent();
   
  if($this->ajax) //special variable to check if the call is ajax
   {
     $this->f(); 
   }
   
$this->setTemplate(_PS_THEME_DIR_.'custom-page.tpl');
}
 
 public function f() {
        return 'messaggio prova';
       }
 
 
 
 
custom_page.tpl
  $.ajax({
       type: "POST",
       controller: 'controllers/front/CustomPageController',
       contentType: "application/json",
       dataType: "json",
       data: JSON.stringify({
          
       }),
       success: function(response) {
           alert(response+"succ");
       },
       error: function(response) {
           alert(response+"err");
       }
});
 

 

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...