Smarty fetch vs smarty display

I have to display a small template inside a main template such that the small template is displayed based on the ajax reposne.I have gotten to the stage where I am getting the parameter after an ajax request.

$smarty=new Smarty(); 
if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])
    &&$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
{
    // echo  "<pre>";
     //print_r("Yes");
     //echo "</pre>";
     echo $smarty->fetch('../templates/small-page.tpl');
} else {
     $smarty->display('../templates/index-page.tpl'); 
}

Here the echo statement is not working .When I uncomment the print_r function I can see in firebug that the html contains "Yes" but it's not displayed on the page. Any help is appreciated.

If the output of your smarty template is in XML format, you can use the responseXML property of xmlhttp, but only if php outputs the correct mime-type.

try :

header("content-type: text/xml");
echo $smarty->fetch('../templates/small-page.tpl');

and then on the client side,

alert(xmlhttp.responseXML);

Tell me if it works !

I don't think Smarty is involved in your problem. Smarty outputs whatever comes out of the processing of its compiled template.

Imagine "Yes" comes out.

On the client side, you have

xmlhttp.onreadystatechange=function() { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
        //Not sure how to diplay a smarty template as a result of responseText or responseXMl 
     } 
}

responseText will hold "Yes". so for example, try:

xmlhttp.onreadystatechange=function() { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
        alert(xmlhttp.responseText);
     } 
}

If this works, you will have to decide what you want to do with the text.