Jump to content

Get HTML block from .tpl file using AJAX without Header & Footer


sphinx.ganesh

Recommended Posts

Hello,

          I'm trying to call Ajax containing the HTML from .tpl file. But the html contains Header and Footer which applied for the theme. I want only that specific block, so i can place it other page.

 

Here is the code -

AJAX Call from .js -

 

$("#message_occasion").change(function() {

if($(this).val()=='')

{

$('#disp_giftcard_contents').html('');

}

else

{

$.ajax({

type:'post',

url:baseUri + 'index.php?controller=giftgallery',

data:'occasion_id='+$(this).val(),

success:function(resp)

{

$('#disp_giftcard_contents').html(resp);

}

});

}

});

 

--------------------------------------------------------------------------------

 

GiftGalleryController -

 

class GiftGalleryController extends FrontController{

public $php_self = 'giftgallery';

 

public function setMedia()

{

parent::setMedia();

 

$this->addJS(_THEME_JS_DIR_.'checkout.js');

$this->addJS(_THEME_JS_DIR_.'image-picker.js');

$this->addCSS(_THEME_CSS_DIR_.'image-picker.css');

}

 

public function init() {

parent::init();

$this->display_column_left = false;

$this->display_column_right = false;

}

 

public function initContent() {

parent::initContent();

 

if(isset($_REQUEST['occasion_id']) && $_REQUEST['occasion_id']!='')

{

$occasion_gallery = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('

SELECT gallery_id, image_url, image_title, occasion_id

FROM '._DB_PREFIX_.'gift_gallery WHERE occasion_id = '.$_REQUEST['occasion_id'].' AND active=1 order by occasion_id asc');

 

$this->context->smarty->assign(array(

'occasion_gallery' => $occasion_gallery

));

 

$this->setTemplate(_PS_THEME_DIR_.'gift-gallery.tpl');

}

}

}

 

--------------------------------------------------------------------------------

 

gift-gallery.tpl -

 

<select class="image-picker masonry show-html" id="message_giftgallery" name="message_giftgallery" autocomplete="off">

{foreach from=$occasion_gallery item=og}

<option data-img-src="{$og['image_url']}" data-img-label='{$og['image_title']}' value="{$og['gallery_id']}">{$og['image_title']}</option>

{/foreach}

</select>

 

 

As you can see, i need only dropdown box to be get as response from Ajax, but i'm getting whole HTML. What should i do for this ?

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