ajax ile bir sayfayı yenilerken karşılaştığım en büyük problem. her yenilenecek yer için sayfayı tekrar oluşturmak idi.

mesela bir listeniz olduğunu düşünelim il ilkçe listesi gibi.

ili seçince ilçeler otomatik gelecek

ajax ile ilce listesini getirmek istediginiz ilce listesinin olduğu yeri ayri bir sayfa olarak tasarlamaniz gerekiyor.

işte bu problemi çözmek için kendi uydurduğum smarty post filter şöyle;

index.php icerigi
<?php
header ('Content-type: text/html; charset=utf-8');

function reRender($tpl_output, &$smarty){
    global $_POST;
    if($_POST["reRender"]!=''){
        preg_match('#<div id="'.$_POST["reRender"].'">(.*?)</div>#si',$tpl_output,$new_tpl_output);
        $tpl_output = $new_tpl_output[1];
        return $tpl_output;
    }else{
        return $tpl_output;    
    }
}

define('SMARTY_DIR', 'mainLib/');
require_once(SMARTY_DIR . 'Smarty.class.php');


$smarty = new Smarty();

$smarty->template_dir = './';
$smarty->compile_dir  = 'tmp/';
$smarty->cache_dir    = 'tmp/';

$smarty->assign('isim','Süleyman');

$liste1 = array('0'=>'Seçiniz',1 => '1.Seçenek', 2=> '2. Seçenek',3 => '3.Seçenek');

$liste2[0] = array(0 => '1', 1 => '2',2 => '3');
$liste2[1] = array(0 => 'Armut', 1 => 'Elma',2 => 'Nane');
$liste2[2] = array(0 => 'Masa', 1 => 'Sandelye',2 => 'Mouse');
$liste2[3] = array(0 => 'Masa', 1 => 'Sandelye',2 => 'Mouse');

$smarty->assign('liste1', $liste1);
$smarty->assign('liste2', $liste2[$_POST["liste1"]]);
$smarty->assign('liste1select', $_POST["liste1"]);
$smarty->register_outputfilter('reRender');
$smarty->display('main.html');

?>
main.html icerigi

<script language="javascript" src="mainLib/jquery.js"></script>
{literal}
<script language="javascript">
    function yukle(){
        $.ajax({type: 'POST',url: 'index.php',data: $('#testForm').serialize(),success: function(ajaxResponse) {$('#liste2').html(ajaxResponse);}});
        
    }
</script>
{/literal}
<form name="testForm"  id="testForm" action="index.php">
Liste1: {html_options name=liste1 options=$liste1 selected=$liste1select}
Liste2: 
<div id="liste2">
{html_options name=liste2 options=$liste2 selected=$liste2select}
</div>
<input name="reRender" value="liste2" />
<input type="button" onclick="yukle();" value="Yükle" />
</form>
aslında başlangıç ve bitiş tagı için <!-- -> gibi açıklama satırları kullanılması daha mantıklı gibi.

fikir vermesi anlamında